Lec6 Lab CSC371 Database Systems
Lec6 Lab CSC371 Database Systems
(Lab)
(Spring2020)
Abdul Qayyum [email protected]
Samia Arshad [email protected]
Faisal Mumtaz [email protected]
1
Previous Lecture Review
SQL Constraints
CHECK
INDEX
FOREIGN KEY
2
Create table
CREATE TABLE Branch (
branchNo varchar(10) NOT NULL PRIMARY KEY,
street varchar(50),
city varchar(50),
postcode varchar(20),
);
3
Tables
4
Agenda
Data Insertion
Data Retrieval from single table
5
The SQL INSERT INTO Statement
Syntax
INSERT INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
6
Insert in different column order
Insert into Branch (street,branchNo,city,postcode)
Values('London','22 Deer Rd','B005','SW1 4EH')
7
Insert with NULL
8
Insert into Branch1
Values('B008','22 Deer Rd','London',NULL)
9
Insert into Branch1 (branchNo,street,city)
Values('B010','22 Deer Rd','London')
10
Insert more than one record
Insert into Branch1 (branchNo,street,city,postcode)
Values('B002','56 Clover Dr','London','NW10 6EU'),
('B003','163 Main St','Glasgow','G11 9QX'),
('B004','32 Manse Rd','Bristol','BS99 1NZ'),
('B007','16 Argyll St','Aberdeen','AB2 3SU');
11
Data Retrieval
Simple statement to retrieve data from table with all attribute and all
records
Select * from table_name
Select * from branch
Select branchNo,street,city,postcode from branch
12
Retrieve Data with specific attributes
Select branchNo,city from branch
13
Retrieve Data with different order of
attributes
Select city,postcode,branchNo,street from branch
14
Can we retrieve city names where our
organization have branches?
Select city from branch Select distinct city from branch
15
Can we see the branches in London city?
16
Summary
Data Insertion
Data Retrieval from single table
17