Lab Manual No. 2
Lab Manual No. 2
CLO’s:
CLO-1
Semester:
Spring 2020
AIR UNIVERSITY ISLAMABAD
FACULTY OF ELECTRICAL AND COMPUTER ENGINEERING
SQL can be divided into two parts: The Data Manipulation Language (DML) and the Data
Definition Language (DDL).
The query and update commands form the DML part of SQL:
• SELECT - extracts data from a database
• UPDATE - updates data in a database
• DELETE - deletes data from a database
• INSERT INTO - inserts new data into a database
The DDL part of SQL permits database tables to be created or deleted. It also define indexes
(keys), specify links between tables, and impose constraints between tables.
The second form specifies both the column names and the values to be inserted:
5 Tjessem Jakob
Note: Notice the WHERE clause in the UPDATE syntax. The WHERE clause specifies which
record or records that should be updated. If you omit the WHERE clause, all records will be
updated!
Now we want to update the person "Tjessem, Jakob" in the "Persons" table. We
use the following SQL statement:
UPDATE Persons
SET Address='Nissestien 67', City='Sandnes'
WHERE LastName='Tjessem' AND FirstName='Jakob'
Note: Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies which
record or records that should be deleted. If you omit the WHERE clause, all records will be
deleted!
Now we want to delete the person "Tjessem, Jakob" in the "Persons" table.
We use the following SQL statement:
DELETE FROM Persons
WHERE LastName='Tjessem' AND FirstName='Jakob'
The "Persons" table will now look like this:
P_Id LastName FirstName Address City
Note: Be very careful when deleting records. You cannot undo this statement!
and
SELECT * FROM table_name
Example
The "Persons" table:
Now we want to select the content of the columns named "LastName" and "FirstName" from
the table above.
We use the following SELECT statement:
Hansen Christ
Svendson Tove
Pettersen Michael
SELECT * Example
Now we want to select all the columns from the "Persons" table. We use the following SELECT
statement:
SELECT * FROM Persons
Tip: The asterisk (*) is a quick way of selecting all columns! The
result-set will look like this:
Example
The "Persons" table:
P_Id LastName FirstName Address City
Now we want to select only the distinct values from the column named "City" from the table above
We use the following SELECT statement:
SELECT DISTINCT City FROM Persons
Lab Tasks:
TASK 1:
Create the following table using SQL and using the INSERT INTO command, insert the
following values in the table created.
Name Reg_No Courses Course_Code Offered_By
Ikram 09 DIP
Hassan 10
AIR UNIVERSITY ISLAMABAD
FACULTY OF ELECTRICAL AND COMPUTER ENGINEERING
TASK 2:
Using the UPDATE statement, update the above table for the following values:
TASK 3:
Select distinct values from the above two tables for the last three columns.
AIR UNIVERSITY ISLAMABAD
FACULTY OF ELECTRICAL AND COMPUTER ENGINEERING