SQL Syntax

The SQL syntax is a standard syntax that is followed while implementing SQL statements, it has a set of rules and guidelines. SQL statements start with the keywords such as INSERT, DELETE, UPDATE, CREATE, ALTER, DROP, etc.SQL is case insensitive which means INSERT and insert both have the same meaning in SQL statements.

SQL Syntax

 

 

Various SQL Syntax 

 

SQL SELECT Statement

The Select statement retrieves data from tables. We can use only the required columns

by specifying column names or simply we can use the * symbol to select all columns. The select clause is always used in front of from clause.

To select the required columns below is the syntax.

SELECT column_1, column_2,column_3….column_N
FROM tablename;

To select all columns below is the syntax

select * from tablename

SQL WHERE Clause

The where clause is used to filter data or to apply filter conditions to get the required result set

SQL syntax:-

SELECT column_1, column_2,column_3….column_N
FROM tablename Where  condition

SQL DISTINCT Clause

The distinct clause is used to get distinct data values from single or multiple columns.

SQL syntax:-

SELECT distinct column_1, column_2,column_3….column_N
FROM tablename

SQL IN Clause

The In clause used to filter the list of values.

SELECT  column_1, column_2,column_3….column_N
FROM tablename
WHERE columnname IN (val1, val2,…val_N)

SQL OR/AND Clause

The OR/AND clause:-

OR clause used to check either true condition.AND clause used to check both the condition true.

SELECT column_1, column_2….column_N
FROM tablename
WHERE condition1{AND|OR} condition2

SQL BETWEEN Clause

The between clause is used to retrieve data from a specified range of values.

SELECT column_1, column_2….column_N
FROM tablename
WHERE column_name BETWEEN val1 AND val2

SQL LIKE Clause

Like clause is used to retrieve data based on a specific pattern.

SELECT column_1, column_2….column_N
FROM tablename
WHERE column_name LIKE (PATTERN )

SQL ORDER BY Clause

The ORDER BY keyword sorts the records in ascending or descending order. By default, the sort order is ascending. To sort records in descending order we have to use the DESC keyword. and for ascending order, we have to use ASC.

SELECT column_1, column_2….columnN
FROM tablename
WHERE CONDITION
ORDER BY columnname

SQL GROUP BY Clause

The GROUP BY  used with aggregate functions such as ( COUNT() , MAX() , MIN() , SUM() , AVG() ) to group the resultset based on one or more columns.

SELECT SUM(columnname)
FROM tablename
WHERE CONDITION
GROUP BY column_name;

SQL HAVING Clause

The HAVING clause is used in SQL syntax along with aggregate functions. We can not use the WHERE clause with aggregate functions.

SELECT SUM(columnname)
FROM tablename
WHERE CONDITION
GROUP BY columnname
HAVING (arithematic condition)

SQL CREATE TABLE Statement

Create  Table used to create a new table in a database.

CREATE TABLE tablename(
column_1 datatype,
column_2 datatype,
column_3 datatype,
…..
column_N datatype,
PRIMARY KEY
)

SQL DROP TABLE Statement

drop table statement used to drop table from database

DROP TABLE table_name

SQL CREATE INDEX Statement

CREATE INDEX statement used to create a new index on the table

CREATE UNIQUE INDEX indexname
ON tablename ( column_1, column_2,…column_N)

SQL DROP INDEX Statement

drop index statement used to drop an index from a particular table

ALTER TABLE tablename
DROP INDEX indexname

SQL INSERT statement

Insert statement used to insert data in the table. We can insert data using a simple select statement or from a complex select statement.

INSERT INTO table_name( column_1, column_2….column_N)
VALUES ( value_1, value_2….value_N)

SQL UPDATE Statement

Update statement used to update data in the table

UPDATE table_name
SET column1 = value_1,….columnN=value_N
[ WHERE condition]

SQL DELETE Statement

Delete statement used to delete data in the table. We can apply a filter to delete required data from the specific table or we can delete whole data from a table without specifying condition. We can delete data from a table using the join condition.

DELETE FROM tablename
WHERE {condition}

 

We can perform database operations using   SQLSyntax

 

4 thoughts on “SQL Syntax”

Comments are closed.