You are on page 1of 3

Muahmmad Haroon Naseem database lab mid

FA20-BCE-034
create database labmid
use labmid

create table Branch(


branchno varchar(234) not null primary key,
street varchar(234),
city varchar(234),
postcode varchar(234),

);

insert into branch(branchno,street,city,postcode) values('B005','22 Deer


Rd','London','SW14EH'),('B007','16 Argyll st','Aberdeen','AB23SU'),('B003','163 Main
St','Glasgow','G119QX')

create table PrivateOwner(


ownerno varchar(234) ,
fname varchar(234),
lname varchar(234),
addres varchar(234),
telno varchar(234),
email varchar(234),
constraint oe primary key(ownerno)

);

insert into PrivateOwner(ownerno,fname,lname,addres,telno,email)


values('CO46','Joe','Keogh','2 Fergus DR,Aberdeen AB27SX','0112-
861212','jkeogh@lhh.com'),

('CO87','carol','Farrel','6 Achray St,Glasgow G32 9DX','0141-357-


7419','efarrel@gmail.com'),

('CO40','Tina','Murphy','63 Well St Glasgow G42','0141-943-1728','tinam@hotmail.com')

create table Staff(


staffno varchar(234),
fname varchar(234),
lname varchar(234),
position varchar(234),
sex varchar(234),
dob date,
salry int,
branchno varchar(234),

constraint st primary key(staffno),

constraint fk foreign key(branchno) references branch(branchno)


);
Muahmmad Haroon Naseem database lab mid
FA20-BCE-034

insert into Staff


(staffno,fname,lname,position,sex,dob,salry,branchno)values('Sl21','john','White','Manage
r','M','1-oct-45',30000,'B005'),

('SG37','Ann','Beech','Assistant','F','10-nov-60',12000,'B003'),

('SG14','david','Ford','Supervisor','M','24-march-58',18000 ,'B003')

create table PropertyForRent(

propertyno varchar(234),
street varchar(234),
city varchar(234),
postcode varchar(234),
typee varchar(234),
rooms int,
rent int,
ownerno varchar(234),
staffno varchar(234),
branchno varchar(234),

constraint pn primary key(propertyno),

constraint fko foreign key(ownerno) references PrivateOwner(ownerno),

constraint fks foreign key(staffno) references staff(staffno),

constraint fkb foreign key(branchno) references branch(branchno)

);
insert into
PropertyForRent(propertyno,street,city,postcode,typee,rooms,rent,ownerno,staffno,branchno
)values('PA14','16 Holhead','Aberdeen','AB7SSU','House',6 ,650 ,'CO46','SA9','B007'),

('Pl94','6 Agryll St','London','NW2','Flat',4 , 400,'CO87','SL41','B005'),

('PG4','6 lawrrence St','Glasgow','G119QX','Flat',3 ,350 ,'CO40',NULL,'B003')

select* from branch

select* from PrivateOwner

select* from PropertyForRent

select* from Staff

/* Queries */
select city+ +street+ +propertyno as addres from PropertyForRent where rooms>4 and
rent<500

alter table Staff add Joining_date varchar(234)


insert into Staff (Joining_date) values('6-march-2002')
Muahmmad Haroon Naseem database lab mid
FA20-BCE-034
select avg(salry) from Staff where branchno='B003'

select fname+ +lname as fullname from PrivateOwner where email like '%hotmail.com'

select sum(rent) from PropertyForRent where typee ='Flat'

select fname+ lname as fullname from Staff where sex='F' and position='Assistant'

select staffno from PropertyForRent where city='Glasgow'

update Staff set Avg(salry)=20000 where position='Manager'

select propertyno ,ownerno from PropertyForRent where rent= min(rent)

You might also like