Syntax and Keywords

SQL (Structured Query Language) is a programming language that manages and manipulates relational databases. It is used to create, modify, and query databases. SQL syntax is the rules defining how SQL statements are written and executed. SQL keywords are the reserved words used in SQL statements to perform specific tasks.

SQL Syntax

SQL syntax is divided into several categories, including Data Definition Language (DDL), Data Manipulation Language (DML), Data Control Language (DCL), and Transaction Control Language (TCL).

Data Definition Language (DDL)

DDL is used to define the structure of a database. It includes commands such as CREATE, ALTER, and DROP.

  • CREATE: used to create a new database, table, view, or index.
  • ALTER: used to modify the structure of an existing database object.
  • DROP: used to delete a database object.

Data Manipulation Language (DML)

DML is used to manipulate data within a database. It includes commands such as SELECT, INSERT, UPDATE, and DELETE.

  • SELECT: used to retrieve data from one or more tables.
  • INSERT: used to insert new data into a table.
  • UPDATE: used to modify existing data in a table.
  • DELETE: used to delete data from a table.

Data Control Language (DCL)

DCL is used to control access to a database. It includes commands such as GRANT and REVOKE.

  • GRANT: used to give users permission to access a database object.
  • REVOKE: used to remove users’ permission to access a database object.

Transaction Control Language (TCL)

TCL is used to manage transactions within a database. It includes commands such as COMMIT and ROLLBACK.

  • COMMIT: used to save changes made to a database.
  • ROLLBACK: used to undo changes made to a database.
  • SAVEPOINT: used to temporarily save a transaction so you can roll back to that point whenever necessary

SQL Keywords

SQL keywords are the reserved words used in SQL statements to perform specific tasks. Some of the most commonly used SQL keywords include:

  • SELECT: used to retrieve data from one or more tables.
  • FROM: used to specify the table(s) from which to retrieve data.
  • WHERE: used to filter data based on a specified condition.
  • ORDER BY: used to sort data in ascending or descending order.
  • GROUP BY: used to group data based on a specified column.
  • JOIN: used to combine data from two or more tables based on a related column.
  • UNION: used to combine the results of two or more SELECT statements into a single result set.

Further Readings

Last updated on