You are on page 1of 3

create table Branch1(

branchNo char(20) primary key,


street varchar(20),
city varchar(10),
postcode char(20));
select *from Branch1;

insert into Branch1(branchNo, street, city, postcode) values


('B005','22 Deer road','London','SW14EH'),
('B007','16 Argyll St','Aberdeen','AB23SU'),
('B003','163 Main St','Glasgow','G119QX'),
('B004','32Manse Rd','Bristol','BS99INZ'),
('B002','56 Clover Dr','London','NW106EU');
select *from Branch1;

create table Staff1(


staffNo char(10) primary key,
fName varchar(20),
lName varchar(20),
position varchar(20),
sex varchar(5),
DOB char(20),
salary int,
branchNo char(20) FOREIGN KEY REFERENCES Branch(branchNo));
select *from Staff1;

insert into Staff1(staffNo,fName,lName,position,sex,DOB,salary,branchNo)values


('SL21','John','White','Manager','M','1-Oct-45','30000','B005'),
('SG37','Ann','Beech','Assistant','F','10-Nov-60','12000','B003'),
('SG14','David','Ford','Supervisor','M','24-Mar-58','18000','B003'),
('SA9','Mary','Howe','Assistant','F','19-Feb-70','9000','B007'),
('SG5','Susan','Brand','Manager','F','3-Jun-40','24000','B003'),
('SL41','Julie','Lee','Assistant','F','13-Jun-65','9000','B005');
select *from Staff1;

create table privateOwner1(


OwnerNo varchar(10) primary key,
fname varchar(15),
lname varchar(15),
address varchar(35),
telnum varchar(20),
email varchar(35),
password varchar(40),
);
insert into privateOwner1(OwnerNo,fname,lname,address,telnum,email,password) values
('CO46','Joe','Keogh','2 Fergus Dr. Aberdeen AB2 ','01224-861212',
'jkeogh@lhh.com', null),
('CO87','Carol','Farrel','6 Achray St. Glasgow G32 9DX','0141-357-7419',
'cfarrel@gmail.com', null),
('CO40','Tina','Murphy','63 Well St. Glasgow G42','0141-943-1728',
'tinam@hotmail.com', null),
('CO93','Tony','Shaw','12 Park Pl. Glasgow G4 0QR','0141-225-7025',
'tony.shaw@ark.com', null);

select * from privateOwner1;


create table PropertyForRent2(
propertyNo varchar(25) primary key,
street varchar(25),
city varchar(25),
postcode varchar(25),
type varchar(25),
rooms int,
rent int,
OwnerNo varchar(10) FOREIGN KEY REFERENCES privateOwner1(OwnerNo),
staffNo char(10) FOREIGN KEY REFERENCES Staff1(staffNo),
branchNo char(20) FOREIGN KEY REFERENCES Branch1(branchNo));

insert into
PropertyForRent2(propertyNo,street,city,postcode,type,rooms,rent,OwnerNo,staffNo,br
anchNo)values
('PA14','16 Holhead','Aberdeen','AB7 5SU','House',6,650,'CO46','SA9','B007'),
('PL94','6 Argyll St','London','NW2','Flat',4,400,'CO87','SL41','B005' ),
('PG4','6 Lawrence St','Glasgow','G11 9QX','Flat',3,350,'CO40', NULL, 'B003'),
('PG36','2 Manor Rd','Glasgow','G32 4QX','Flat',3,375,'CO93','SG37','B003' ),
('PG21','18 Dale Rd','Glasgow','G12','House',5,600,'CO87','SG37','B003'),
('PG16','5 Novar Dr','Glasgow','G12 9AX','Flat',4,450,'CO93','SG14','B003' );

select * from PropertyForRent2;

create table Client1


(
clientnum varchar(6) primary key,
fname varchar(15),
lname varchar(15),
telnum varchar(20),
preftype varchar(12),
maxrent int,
email varchar(35),
);
insert into client1(clientnum,fname,lname,telnum,preftype,maxrent,email) values
('CR76','John','Kay','0207-774-5678','Flat',425,'john.kay@gmail.com'),
('CR54','Alien','Stewart','0209-876-7487','Flat',350,'astwert@gmail.com'),
('CR74','Mike','Ritchie','0285-764-8722','House',750,'mike.ritchie@gmail.com'),
('CR62','Marry','Trigear','0209-029-0987','Flat',600,'marry.tri@gmail.com');
select * from client1;

create table Viewing1(


clientNo varchar(10) ,
propertyNo varchar(10),
primary key (clientNo,propertyNo),
viewDate varchar(14),
comment varchar(30)
);
insert into Viewing1(clientNo,propertyNo,viewDate,comment) values
('CR56','PA14','24-may-13','too small'),
('CR76','PG4','20-april-14','too remote'),
('CR56','PG4','26-may-13',''),
('CR62','PA14','14-may-13','no dining room'),
('CR56','PG36','28-april-13','');
select * from Viewing1;
create table Registration1(
clientNo varchar(20),
branchNo varchar(10),
primary key(clientNo,branchNo),
staffNo char(10) foreign key references Staff(staffNo),
dateJoined varchar(10));

insert into Registration1(clientNo, branchNo, staffNo, dateJoined)values


('CR76','B005','SL41','2015-01-13'),
('CR56','B003','SG37','2014-04-13'),
('CR74','B003','SG37','2013-11-16'),
('CR62','B007','SA9','2014-03-07');
select *from Registration1;

SELECT COUNT(BranchNO) as TotalBranches FROM branch1;

SELECT * from branch1 WHERE City='London';

select * from branch1 where branchNo='B002' or branchNo='B005' or branchNo='B007';

SELECT * from branch1 WHERE City in ('Bristol','Glasgow');

select * from Staff1 where lName like 'B%';

select sum(salary) as TotalSalary from staff1 where sex='M';

update staff1
set position= 'Senior Manager' where position= 'Manager';

select * from propertyForRent2 where rooms <4 or rooms <6;

select * from PropertyForRent2;

update PropertyForRent2
set staffNo='SL41' where propertyNo='PA14';

select * from Client1 where email='';

delete from Client1 where clientnum='CR75';

select * from Client1 where maxrent = (select max(maxrent) from Client1);

select * from privateowner1 where email like 'j%';

select * from privateOwner1


inner join PropertyForRent2 on privateOwner1.OwnerNo = PropertyForRent2.OwnerNo;

select * from PropertyForRent2


inner join privateOwner1 on privateOwner1.OwnerNo = PropertyForRent2.OwnerNo
inner join staff1 on PropertyForRent2.staffNo = staff1.staffNo
where propertyNO = 'PA14' ;

You might also like