Dbms-Class-11-Sql Syntax
Dbms-Class-11-Sql Syntax
SQL is followed by a unique set of rules and guidelines called Syntax. This
tutorial 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 all
the statements end with a semicolon (;).
The most important point to be noted here is that SQL is not a case
insensitive, which means SELECT and select have same meaning in SQL
statements.
1. SELECT Statement: This SQL statement reads the data from the SQL
database and shows it as the output to the database user.
This example shows the Emp_ID, First_Name, Last_Name, Salary, and City of
those employees from the Employee_details table whose Salary is 100000. The
output shows all the specified details according to the ascending alphabetical
order of Last_Name.
UPDATE table_name
SET column_name1 = new_value_1, column_name2 = new_value_2, ...., colu
mn_nameN = new_value_N
[ WHERE CONDITION ];
IT-Ramesh 9848353570 1
Example of UPDATE Statement:
UPDATE Employee_details
SET Salary = 100000
WHERE Emp_ID = 10;
3. DELETE Statement:This SQL statement deletes the stored data from the
SQL database.
4. CREATE TABLE Statement: This SQL statement creates the new table
in the SQL database.
IT-Ramesh 9848353570 2
First_name VARCHAR(30),
Last_name VARCHAR(30),
Salary Money,
City VARCHAR(30),
PRIMARY KEY (Emp_Id)
);
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.
The above SQL alter statement adds the column with its datatype in the
existing database table.
The above 'SQL alter statement' renames the old column name to the new
column name of the existing database table.
The above SQL alter statement deletes the column of the existing database
table.
This example adds the new field whose name is Designation with size 18 in
the Employee_details table of the SQL database.
IT-Ramesh 9848353570 3
6. DROP TABLE Statement: This SQL statement deletes or removes the
table and the structure, views, permissions, and triggers associated with
that table.
The above syntax of the drop statement deletes specified tables completely if
they exist in the database.
IT-Ramesh 9848353570 4
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.
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.
10. TRUNCATE TABLE Statement: This SQL statement deletes all the
stored records from the table of the SQL database.
IT-Ramesh 9848353570 5
TRUNCATE TABLE table_name;
This example deletes the record of all employees from the Employee_details
table of the database.
11. DESCRIBE Statement: This SQL statement tells something about the
specified table or view in the query.
DESCRIBE Employee_details;
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.
This example shows the distinct values of the City and Salary column from
the Employee_details table.
IT-Ramesh 9848353570 6
COMMIT
14. ROLLBACK Statement: This SQL statement undo the transactions and
operations which are not yet saved to the SQL database.
ROLLBACK
15. CREATE INDEX Statement: This SQL statement creates the new index
in the SQL database table.
IT-Ramesh 9848353570 7
16. DROP INDEX Statement: This SQL statement deletes the existing index
of the SQL database table.
This example deletes the index idx_First_Name from the SQL database.
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.
USE database_name;
USE Company;
IT-Ramesh 9848353570 8