SQL Syntax
SQL Syntax
SQL Syntax
When you want to do some operations on the data in the database, then you must have to
write the query in the predefined syntax of SQL.
The syntax of the structured query language is a unique set of rules and guidelines, which
is not case-sensitive. Its Syntax is defined and maintained by the ISO and ANSI standards.
Following are some most important points about the SQL syntax which are to remember:
o You can write the keywords of SQL in both uppercase and lowercase, but writing
the SQL keywords in uppercase improves the readability of the SQL query.
o SQL statements or syntax are dependent on text lines. We can place a single
SQL statement on one or multiple text lines.
o You can perform most of the action in a database with SQL statements.
o SQL syntax depends on relational algebra and tuple relational calculus.
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.
Let's discuss each statement in short one by one with syntax and one example:
pg. 1
SQL SYNTAX
1. SELECT Statement
This SQL statement reads the data from the SQL database and shows it as the output to
the database user.
2. UPDATE Statement
This SQL statement changes or modifies the stored data in the SQL database.
1. UPDATE table_name
2. SET column_name1 = new_value_1, column_name2 = new_value_2, ...., column_n
ameN = new_value_N
3. [ WHERE CONDITION ];
Example of UPDATE Statement:
1. UPDATE Employee_details
2. SET Salary = 100000
3. WHERE Emp_ID = 10;
This example changes the Salary of those employees of the Employee_details table
whose Emp_ID is 10 in the table.
pg. 2
SQL SYNTAX
3. DELETE Statement
This SQL statement deletes the stored data from the SQL database.
pg. 3
SQL SYNTAX
This example creates the table Employee_details with five columns or fields in the SQL
database. The fields in the table are Emp_Id, First_Name, Last_Name,
Salary, and City. The Emp_Id column in the table acts as a primary key, which means
that the Emp_Id column cannot contain duplicate values and null values.
pg. 4
SQL SYNTAX
pg. 5
SQL SYNTAX
This example inserts 101 in the first column, Akhil in the second column, Sharma in the
third column, 40000 in the fourth column, and Bangalore in the last column of the
table Employee_details.
pg. 6
SQL SYNTAX
1. DESCRIBE Employee_details;
This example explains the structure and other details about
the Employee_details table.
1. COMMIT
Example of COMMIT Statement:
pg. 7
SQL SYNTAX
1. ROLLBACK
Example of ROLLBACK Statement:
pg. 8
SQL SYNTAX
1. USE database_name;
Example of USE DATABASE Statement:
1. USE Company;
This example uses the company database.
pg. 9