Structured Query Language Prepared By: Reema Agrawal Asst Professor Meri
Structured Query Language Prepared By: Reema Agrawal Asst Professor Meri
Structured Query Language Prepared By: Reema Agrawal Asst Professor Meri
Prepared By:
Reema Agrawal
Asst Professor
MERI
SQL
Structured Query language is a language that
provides an interface to database systems.
Syntax:
INSERT INTO <tablename> values
(<‘expression 1’>, <‘expression2’>);
For specific columns:
INSERT INTO <tablename>
(<columnname1>, <columnname2>)
values (<‘expression 1’>, <‘expression2’>);
Table Name: Employee
Emp_ID Name Designatio Location Salary
n
A10141 Ajay Manager Delhi 75000
A10142 Rahul Executive Delhi 55000
A10143 Shruti Manager Bangalore 80000
A10144 Lokesh VP Bangalore 100000
A10145 Tripti Sales Mumbai 40000
Table Name: Student
Student_R Name Course Location Total
oll No Marks
10126734 Rahul BBA Delhi 500
10117834 Tarun BBA Delhi 586
10128734 Shruti MBA Delhi 540
10118834 Lalit BCA Delhi 523
10126834 Ajay BBA Delhi 596
10118934 Parul MBA Delhi 561
Viewing Data In the Tables:
Once the data has been inserted into a table,
the next logical operation would be to view
what has been inserted.
Entire rows
SELECT DISTINCT * from <tablename>;
Sorting Data In a table
The rows retrieved from the table will be
sorted in either ascending or descending
order depending on the condition specified in
the SELECT sentence.
Syntax:
Select * from <Tablename> order by
<columnname1>;
• Truncating tables:
TRUNCATE TABLE <TableName>;
• Dropping tables:
DROP TABLE <TableName>;
Some Queries:
SELECT * FROM student WHERE name LIKE
'%John%‘ (with either first or last name as JOHN)
SELECT * FROM student WHERE name LIKE 'John
%‘ (with first name JOHN)
SELECT * FROM student WHERE name LIKE
'%John‘ (with last name JOHN)
SELECT * FROM student WHERE name LIKE '%a
%' AND name LIKE '%e%‘ (with either first
alphabet as a or e)