DBMS 5
1)Create the following tables(primary keys are underlined.).(Attemptanytwo)
Property(pno,description,
area)Owner(oname,address,phone)
An owner can have one or more properties,but a property belongs to exactly one
[Link] the relations accordingly,so that the relationship is handled properly
and the relations are in normalizedform (3NF).
create table owner(
oname text primary key,
address text,
phone bigint
);
create table property1(
oname text ,
foreign key (oname) references owner (oname) on delete cascade on update cascade,
pno int primary key ,
des text,
area text
);
create table own_pro(
oname text,
foreign key (oname) references owner (oname) on delete cascade on update cascade,
pno int ,
foreign key (pno) references property1 (pno) on delete cascade on update cascade ,
primary key(oname,pno)
);
a)Insert two records in to owner table.
-> insert into owner values('tushar','pune',9130127002);
insert into owner values('[Link]','pune',9823831472);
b)insert 2 property records for each owner.
->insert into property1 values('[Link]',233,'new ','pune');
insert into property1 values('[Link]',401,'new ','pune');
c)Update phone no of“[Link]”to 9890278008
->update owner set phone=9890278008 where oname='[Link]';
d)Delete all properties from “pune”ownedby“[Link]”
->delete from owner where address='pune' and oname='[Link]';
2) Create the following tables ( primary keys are underlined.).
Emp(eno,ename,designation,sal)
Dept(dno,dname,dloc)
There exists a one-to-many relationship between emp & dept.
Create the Relations accordingly, so that the relationship is handled properly and
the relations are
in normalized form (3NF).
create table dept1(
dno int primary key,
dname text,
dloc text
);
create table emp1(
dno int,
eno int primary key,
ename text,
designation text,
sal money,
foreign key (dno) references dept1 (dno) on delete cascade
);
a) Insert 2 records into department table
->insert into dept1 values(clerk,'computer','pune');
insert into dept1 values(30,'computer1','pune');
b) Insert 2 employee records for each department.
->insert into emp1 values(20,1,'xyz','manager',9000);
insert into emp1 values(30,2,'xyz','staff',5000);
c) increase salary of “managers” by 15%;
->update emp1 set sal=sal*15/100 where ename='staff';
d) delete all employees of deparment 30;
->delete from emp1 where dno=30;
e) delete all employees who are working as a “clerk”
->delete from emp1 where designation='clerk';
f) change location of department 20 to ‘KOLKATA’
->update depet1 set dloc='kolkata' where dno=20
3)
Create the following tables ( primary keys are underlined.).
Sales_order(s_order_no,s_order_date)
Client(client_no, name, address)
A clinet can give on e or more sales_orders , but a sales_order belongs to exactly
one client.
Create the Relations accordingly, so that the relationship is handled properly and
the relations are
in normalized form (3NF).
a) insert 2 client records into client table
b) insert 3 sales records for each client
c) change order date of client_no ’C004’ to 12/4/08
d) delete all sale records having order date before 10th feb. 08
e) delete the record of client “joshi”
Ans:
create table client(
cno int primary key,
name text,
address text
);
create table osales(
cno int ,
ono integer primary key ,
odate date,
foreign key (cno) references client (cno)on delete cascade on update cascade
);
a)
insert into client values(1,'abc','pune');
insert into client values(2,'pqr','pune');
b)
insert into osales values(1,10,'2-2-2022');
insert into osales values(2,20,'2-4-2014');
select *from client;
select *from osales;
c)
update osales set odate='12/4/8' where cno='1';
e)
delete from client where name='joshi';