SQL is observed by a special set of rules and guidelines called Syntax. In this chapter, you will start with SQL by listing all the basic SQL Syntax.
All the SQL commands begin with any of the SQL words like INSERT, UPDATE, SELECT, ALTER, DROP, DELETE, CREATE, USE, SHOW, and all the commands terminate with a semicolon (;).
An important fact to be mentioned is that SQL is case insensitive. It signifies SELECT and select have the same purpose in SQL statements.
SQL CREATE DATABASE Statement:
CREATE DATABASE database_name;
SQL SELECT Statement:
SELECT * FROM table_name;
SQL INSERT INTO Statement:
INSERT INTO table_name( column1, column2….columnN) VALUES ( value1, value2….valueN);
SQL UPDATE Statement:
UPDATE table_name SET column1 = value1, column2 = value2….columnN=valueN [ WHERE CONDITION ];
SQL DELETE Statement:
DELETE FROM table_name WHERE {CONDITION};
SQL DROP DATABASE Statement:
DROP DATABASE database_name;
SQL USE Statement:
USE DATABASE database_name;
SQL COMMIT Statement:
COMMIT;
SQL IN Clause:
SELECT column1, column2….columnN FROM table_name WHERE column_name IN (val–1, val–2,…val–N);
SQL ORDER BY Clause:
SELECT column1, column2….columnN FROM table_name WHERE CONDITION ORDER BY column_name {ASC|DESC};
SQL DISTINCT Clause:
SELECT DISTINCT column1, column2….columnN FROM table_name;
SQL WHERE Clause:
SELECT column1, column2….columnN FROM table_name WHERE CONDITION;
SQL AND/OR Clause:
SELECT column1, column2….columnN FROM table_name WHERE CONDITION–1 {AND|OR} CONDITION–2;
SQL CREATE TABLE Statement:
CREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype, ….. columnN datatype, PRIMARY KEY( one or more columns ) );
SQL CREATE INDEX Statement :
CREATE UNIQUE INDEX index_name ON table_name ( column1, column2,…columnN);
SQL DROP INDEX Statement :
ALTER TABLE table_name DROP INDEX index_name;
SQL DESC Statement :
DESC table_name;
SQL ALTER TABLE Statement:
ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};
SQL ALTER TABLE Statement (Rename) :
ALTER TABLE table_name RENAME TO new_table_name;
SQL TRUNCATE TABLE Statement:
TRUNCATE TABLE table_name;
SQL DROP TABLE Statement:
DROP TABLE table_name;