Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

database sheet 2 // Mhmd Jawad rnum int,

create database mydatabase1 hnum int,


go type varchar(30),
use mydatabase1 price money,
primary key (rnum,hnum),
create table hotel ( foreign key (hnum) references hotel(hnum)
hnum int, on update cascade on delete cascade)
hname varchar(20) unique,
hstar varchar(20),
hlocation varchar(20),
primary key (hnum)) insert into room values (101,1,'single',30)
insert into room values (102,1,'double',50)
insert into hotel values (1,'hilton','fivestar','hamra') insert into room values (1101,4,'presidental suite',3500)
insert into hotel values (2,'marriot','four star','jinah') insert into room values (201,5,'suite',1200)
insert into hotel values (3,'best western','three insert into room values (305,5,'double',25)
star','mar elias')
insert into hotel values (4,'four seasons','five
star','barbeer') create table booking (
insert into hotel values (5,'bristol','two star','hamra') hnum int,
gnum int,
create table guest ( rnum int,
gnum int, datefrom date,
gname varchar(20), dateto date,
gadress varchar(20), primary key (hnum,gnum,rnum,datefrom),
sex varchar(1) check(sex in('f','m')), foreign key (gnum) references guest(gnum)
age int, on delete cascade on update cascade,
salary float, foreign key (rnum,hnum) references room(rnum,hnum)
vip varchar(3) check (vip in('yes','no')),
primary key (gnum)) on delete cascade on update cascade)

insert into guest values (305,'mary insert into booking values


brouwn','london','f',25,2321.5,'yes') (1,503,101,'15/mar/2005','20/mar/2005')
insert into guest values (401,'john insert into booking values
smith','hawaii','m',34,1230,'no') (4,305,1101,'11/jun/2006','20/jun/2006')
insert into guest values (503,'joe insert into booking values
mandoza','salvador','m',21,4325.0,'no') (5,401,201,'1/july/2006','7/july/2006')
insert into guest values (930,'franklin insert into booking values
dobar','usa','m',54,654,'yes') (5,930,305,'5/july/2006','10/july/2006')
insert into booking values
(4,305,1101,'15/mar/2005','20/mar/2005')
insert into booking values
(1,401,101,'1/july/2006','7/july/2006')
create table room (
----------------------------function---------------------------------------
create function totalcost (@price money,@type varchar(20))
returns money
as
begin
if(@type = 'presidential suite')return @price + 0.3*@price;
if(@type = 'suite')return @price + 0.2*@price;
if(@type = 'double')return @price + 0.1*@price;
if(@type = 'single')return @price + 0.05*@price;
return 0;
end
---------------------------------procedure----------------------------------------
create procedure finalprice @tcost money
as
begin
declare @tva money
set @tva = 0.05*@tcost

print 'The price of your room is '+convert(varchar(20),@tcost)+' + '+


convert(varchar(10),@tva)+ ' = '+convert(varchar(20),@tcost+@tva)

end
-------------------main program----------------------------------------------
declare @rtype varchar(20),@rprice money, @z money

select @rtype=[type],@rprice=price from room inner join booking on room.rnum=booking.rnum and gnum = 503 and
room.rnum = 101

set @z =mydatabase1.dbo.totalcost (@rprice,@rtype)


exec dbo.finalprice @z

You might also like