SQL Syntax



SQL is a declarative language; its syntax reads like natural language. SQL statements always start with a verb that describes the action, like SELECT, UPDATE, INSERT, DELETE, etc. . Following the verb comes the subject and the predicate.

The syntax of SQL is controlled by the International Organization for Standardization (ISO) and the American National Standards Institute (ANSI).


SQL Statement

SQL statements are simple and straightforward, like natural English.

SQL statements start with any of SQL commands like SELECT, UPDATE, INSERT, DELETE, etc., and are terminated by a semicolon ;.

The following example shows a valid SQL statement:

SELECT <column_name_1>, <column_name_2>
FROM <table_name>;

Use Semicolon after SQL Statements

It is considered a best practice to use a semicolon at the end of an SQL statement. Some database systems require a semicolon at the end of each SQL statement.

Semicolon is used to terminate and submit statements to the database server. Using a semicolon at the end of each statement is the standard way to separate SQL statements in a database system in which more than one SQL statement is used in the same call to the database server.


Case Sensitivity in SQL

SQL keywords are not case-sensitive that means typing SELECT is the same as typing select. However, the database, table names, and columns can be case-sensitive depending on the operating system the database server is running. Generally, Unix/Linux operating systems are case-sensitive, whereas Windows operating systems are not.

Note: It is recommended and a best practice to write SQL keywords in uppercase to separate them from other text in a SQL statement for better clarity.


SQL Comments

A comment is simply a text that is ignored or not interpreted by the database engine. Comments are used to explains what a specific SQL statement is doing or to prevent the execution of SQL statements.

SQL supports a single-line as well as multi-line comments.

If you want to write a single-line comment, start the line with two consecutive hyphens -- as the following example:

-- Select all students
SELECT * FROM student;

On the other hand, if you want to write a multi-line comment, start with a slash followed by an asterisk /* and end the comment with an asterisk followed by a slash */, like the following example:

/* 
Select all students which 
age is greater or equals 18
*/
SELECT * FROM student 
WHERE age >= 18;

SQL Commands

The following list shows some of the most used and important SQL commands:

  • SELECT : It is used to retrieve data from a database.
  • INSERT INTO: Inserts new data into a database.
  • UPDATE: Modifies data in a database.
  • DELETE: Removes data from a database.
  • CREATE DATABASE: Creates a new database.
  • ALTER DATABASE: Modifies a database.
  • CREATE TABLE: Creates a new table.
  • ALTER TABLE: Modifies a table.
  • DROP TABLE: Removes a table.
  • CREATE INDEX: It is used to create an index (search key).
  • DROP INDEX: Deletes an index.


ExpectoCode is optimized for learning. Tutorials and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy.
Copyright 2020-2021 by ExpectoCode. All Rights Reserved.