SQL Syntax

SQL Statement

SQL statements tell the database what operation you want to perform on the structured data and what information you would like to access from the database. SQL are very simple and easy to use and understand. 

Simple Example of SQL statement:

SELECT "column_name" FROM "table_name";    

SQL statement begins with any of the SQL keywords and ends with the semicolon (;). The semicolon is used in the SQL for separating the multiple Sql statements which are going to execute in the same call. In this SQL tutorial, we will use the semicolon (;) at the end of each SQL query or statement.

Important SQL Statements 

  1. Select Statement
  2. Update Statement
  3. Delete Statement
  4. Create Table Statement
  5. Alter Table Statement
  6. Drop Table Statement
  7. Create Database Statement
  8. Drop Database Statement
  9. Insert Into Statement
  10. Truncate Table Statement
  11. Describe Statement
  12. Distinct Clause
  13. Commit Statement
  14. Rollback Statement
  15. Create Index Statement
  16. Drop Index Statement
  17. Use Statement


Let's discuss each statement in short one by one with syntax and one example:

1. SELECT Statement

This SQL statement reads the data from the SQL database and shows it as the output to the database user.

Syntax of SELECT Statement:

 SELECT column_name1, column_name2, .…, column_nameN  

    [ FROM table_name ]  

    [ WHERE condition ]  

    [ ORDER BY order_column_name1 [ ASC | DESC ], .... ];  


2. UPDATE Statement

This SQL statement changes or modifies the stored data in the SQL database.

Syntax of UPDATE Statement:

UPDATE table_name  
SET column_name1 = value_1, column_name2 = value_2, ...., column_nameN = value_N  
WHERE  CONDITION ]
;  


3. DELETE Statement

This SQL statement deletes the stored data from the SQL database.

Syntax of DELETE Statement:

DELETE FROM table_name  
WHERE CONDITION ];  

4. CREATE TABLE Statement

This SQL statement creates the new table in the SQL database.

Syntax of CREATE TABLE Statement:

CREATE TABLE table_name  
(  
column_name1 data_type [column1 constraint(s)],  
column_name2 data_type [column2 constraint(s)],  
.....  
.....,  
column_nameN data_type [columnN constraint(s)],  
PRIMARY KEY(one or more col)  
);  

5. ALTER TABLE Statement

This SQL statement adds, deletes, and modifies the columns of the table in the SQL database.

6. DROP TABLE Statement

This SQL statement deletes or removes the table and the structure, views, permissions, and triggers associated with that table.

7. CREATE DATABASE Statement

This SQL statement creates the new database in the database management system.

8. DROP DATABASE Statement

This SQL statement deletes the existing database with all the data tables and views from the database management system.

9. INSERT INTO Statement

This SQL statement inserts the data or records in the existing table of the SQL database. This statement can easily insert single and multiple records in a single query statement.

10. TRUNCATE TABLE Statement

This SQL statement deletes all the stored records from the table of the SQL database.

11. DESCRIBE Statement

This SQL statement tells something about the specified table or view in the query.

12. DISTINCT Clause

This SQL statement shows the distinct values from the specified columns of the database table. This statement is used with the SELECT keyword.

13. COMMIT Statement

This SQL statement saves the changes permanently, which are done in the transaction of the SQL database.

14. ROLLBACK Statement

This SQL statement undo the transactions and operations which are not yet saved to the SQL database.

15. CREATE INDEX Statement

This SQL statement creates the new index in the SQL database table.

16. DROP INDEX Statement

This SQL statement deletes the existing index of the SQL database table.

17. USE Statement

This SQL statement selects the existing SQL database. Before performing the operations on the database table, you have to select the database from the multiple existing databases.



Post a Comment

0 Comments

Close Menu