Basic Syntax in SQL Server

SQL is followed by a unique set of rules and guidelines called Syntax. This Article gives
you a quick start with SQL by listing all the basic SQL Syntax: All the SQL statements start
with any of the keywords like SELECT, INSERT, UPDATE, DELETE, ALTER, DROP,
CREATE, USE, SHOW and the entire statement ends with a semicolon (;). Important point
to be noted is that SQL is case insensitive which means SELECT and select have same meaning in SQL statements but MySQL makes a difference in table names. So if you are working with MySQL then you need to give table names as they exist in the database.

SELECT Statement:
SELECT column1, column2….columnN FROM table_name;

DISTINCT Clause:
SELECT DISTINCT column1, column2….columnN FROM table_name;

WHERE Clause:
SELECT column1, column2….columnN FROM table_name WHERE CONDITION;

AND/OR Clause:
SELECT column1, column2….columnN FROM table_name WHERE CONDITION-1 {AND|OR} CONDITION-2;

IN Clause:
SELECT column1, column2….columnN FROM table_name WHERE column_name IN (val-1, val-2,…val-N);

BETWEEN Clause:
SELECT column1, column2….columnN FROM table_name WHERE column_name BETWEEN val-1 AND val-2;

Like :
SELECT column1, column2….columnN FROM table_name WHERE column_name LIKE { PATTERN };

ORDER BY :
SELECT column1, column2….columnN FROM table_name WHERE CONDITION ORDER BY column_name {ASC|DESC};

GROUP BY :
SELECT SUM(column_name) FROM table_name WHERE CONDITION GROUP BY column_name;

COUNT :
SELECT COUNT(column_name) FROM table_name WHERE CONDITION;

HAVING :
SELECT SUM(column_name) FROM table_name WHERE CONDITION GROUP BY column_name HAVING (arithematic function condition);

CREATE TABLE Statement::
CREATE TABLE table_name( column1 datatype, column2 datatype, column3 datatype, ….. columnN datatype, PRIMARY KEY( one or more columns ) );

DROP TABLE Statement::
DROP TABLE table_name;

CREATE INDEX :
CREATE UNIQUE INDEX index_name ON table_name ( column1, column2,…columnN);

DROP INDEX :
ALTER TABLE table_name DROP INDEX index_name;

TRUNCATE :
TRUNCATE TABLE table_name;

ALTER :
ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};

Statement (Rename):
ALTER TABLE table_name RENAME TO new_table_name;

INSERT INTO :
INSERT INTO table_name( column1, column2….columnN) VALUES ( value1, value2….valueN);

UPDATE:
UPDATE table_name SET column1 = value1, column2 = value2….columnN=valueN [ WHERE CONDITION ];

DELETE Statement:



Leave a Reply

Captcha 42 + = 49