SQL
SQL
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
Table Name: Student
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)