Basic T-SQL Syntax

SQL Server Tutorials and Syntax
Post Reply
SQLee
Posts: 1
Joined: Wed Jun 26, 2019 3:42 pm

Wed Jun 26, 2019 4:09 pm

T-SQL is followed by a standard set of guidelines and rules called Syntax.

The Syntax to SQL is case insensitive which means that 'UPDATE' and 'update' are the same thing.

This tutorial gives you a quick start with T-SQL by listing all the basic T-SQL Syntax. needed to perform queries.

All of the T-SQL statements start with unique keywords such as the below:
  • SELECT
    ALTER
    DELETE
    INSERT
    UPDATE
    DROP
    TRUNCATE
    CREATE
    USE
The statements in T-SQL end with a semicolon (;).

Below is some standard Syntax in SQL:


SQL SELECT Statement

Code: Select all

SELECT Column_A, Column_B....Column_Z
FROM   table_name;
SQL DISTINCT Clause

Code: Select all

SELECT DISTINCT Column_A, Column_B....Column_Z
FROM   table_name;
SQL WHERE Clause

Code: Select all

SELECT Column_A, Column_B....Column_Z
FROM   table_name
WHERE  CONDITION;
SQL AND/OR Clause

Code: Select all

SELECT Column_A, Column_B....Column_Z
FROM   table_name
WHERE  CONDITION-1 {AND|OR} CONDITION-2;
IN Clause

Code: Select all

SELECT Column_A, Column_B....Column_Z
FROM   table_name
WHERE  column_name IN (val-1, val-2,...val-N);
SQL BETWEEN Clause

Code: Select all

SELECT Column_A, Column_B....Column_Z
FROM   table_name
WHERE  column_name BETWEEN val-1 AND val-2;
SQL LIKE Clause

Code: Select all

SELECT Column_A, Column_B....Column_Z
FROM   table_name
WHERE  column_name LIKE { PATTERN };
SQL ORDER BY Clause

Code: Select all

SELECT Column_A, Column_B....Column_Z
FROM   table_name
WHERE  CONDITION
ORDER BY column_name {ASC|DESC};
SQL GROUP BY Clause

Code: Select all

SELECT SUM(column_name)
FROM   table_name
WHERE  CONDITION
GROUP BY column_name;
SQL COUNT Clause

Code: Select all

SELECT COUNT(column_name)
FROM   table_name
WHERE  CONDITION;
SQL HAVING Clause

Code: Select all

SELECT SUM(column_name)
FROM   table_name
WHERE  CONDITION
GROUP BY column_name
HAVING (arithematic function condition);
SQL CREATE TABLE Statement

Code: Select all

CREATE TABLE table_name(
Column_A datatype,
Column_B datatype,
column3 datatype,
.....
Column_Z datatype,
PRIMARY KEY( one or more columns )
);
SQL DROP TABLE Statement

Code: Select all

DROP TABLE table_name;
SQL CREATE INDEX Statement

Code: Select all

CREATE UNIQUE INDEX index_name
ON table_name ( Column_A, Column_B,...Column_Z);
SQL DROP INDEX Statement

Code: Select all

ALTER TABLE table_name
DROP INDEX index_name;
SQL DESC Statement

Code: Select all

DESC table_name;
SQL TRUNCATE TABLE Statement

Code: Select all

TRUNCATE TABLE table_name;
SQL ALTER TABLE Statement

Code: Select all

ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};
SQL ALTER TABLE Statement (Rename)

Code: Select all

ALTER TABLE table_name RENAME TO new_table_name;
SQL INSERT INTO Statement

Code: Select all

INSERT INTO table_name( Column_A, Column_B....Column_Z)
VALUES ( value1, value2....valueN);
SQL UPDATE Statement

Code: Select all

UPDATE table_name
SET Column_A = value1, Column_B = value2....Column_Z=valueN
[ WHERE  CONDITION ];
SQL DELETE Statement

Code: Select all

DELETE FROM table_name
WHERE  {CONDITION};
SQL CREATE DATABASE Statement

Code: Select all

CREATE DATABASE database_name;
SQL DROP DATABASE Statement

Code: Select all

DROP DATABASE database_name;
SQL USE Statement

Code: Select all

USE database_name;
SQL COMMIT Statement

Code: Select all

COMMIT;
SQL ROLLBACK Statement

Code: Select all

ROLLBACK;
Feel free to comment with anything I have missed.
Admin2
Site Admin
Posts: 7
Joined: Thu Jun 20, 2019 3:53 pm

Wed Jun 26, 2019 4:10 pm

Thanks @SQLee :D
Post Reply

Social Media