Sei sulla pagina 1di 11

DBMS LAB ASSIGNMENT-1

Submitted by:

NAME- AKASHDEEP BALU,


ROLL NO-101510011

Submitted to:
Mr. Abhishek jain.

LAB ASSIGNMENT-5
1. Create table emp which has the following
attributes (employee
table)
(@empno, ename, job, sal, deptno)
Where empno is primary key, ename is
unique, job in (Prof, AP,
and Lect), sal is not NULL, and deptno default
is 10.
Insert appropriate records, check error
messages in case of
violation and list all the constraint names for
given table.
ans: create table employee27
(
enamevarchar(20)constraint uniquec1
unique,
empnonumber(6)constraint primaryc1
primary key,
job varchar(25) check(job
in('prof','Assistprof','lect')),sal
number(10)constraint notc1 not null,deptno
number(10)default 10
);

insert into employee27


values('sanyam',27,'prof',85000,5);
insert into employee27
values('vineet',29,'lect',44000,10);
insert into employee27
values('rishab',30,'Assistprof',38000,default);

constraints name used:


1.uniquec1
2.primaryc1
3.notc1
select * from user_constraints where
table_name ='EMPLOYEE27';

2. Create table book:


Rno number—PK
DOI-date
DOR-date
DOR>DOI
Insert appropriate records, check error
messages in case of
violation and list all the constraint names for
given table.
ans:
create table book27
(
roll_nonumber(6)constraint primaryc2
primary key,
date_of_issuedate,date_of_return date,
check(date_of_return>date_of_issue)
);

insert into book27 values(2062,'26-jan-


2016','15-aug-2016');
insert into book27 values(2059,'14-feb-
2016','02-oct-2016');

constraints name used:


1.primaryc2

query used:
select * from user_constraints where
table_name ='BOOK27';
3. Create table st
Rno-Number
Class-Char
Marks-Number
Primary key(rno,class)
Marks>0
Insert appropriate records, check error
messages in case of
violation and list all the constraint names for
given table.
ans:
create table st_3
(rnonumber(10),class varchar(6),marks
number(6),constraint primaryc3 primary
key(roll_no,class),check(marks>0));

insert into st_3 values(2062,'11th',85);


insert into st_3 values(3052,'12th',43);
constraints name used:
1.primaryc3

query used:
select * from user_constraints where
table_name ='ST_3';

4. Create table S which has the following


attributes (Salesperson
table)
(sno, sname, city)
Where sno is primary key
ans:
create table S27
(snonumber(8) primary key,sname
varchar(10),city varchar(10));
5. Create table P which has the following
attributes (Part table)
(pno, pname, color)
Where pno is primary key
ans:
create table P27
(pnonumber(10) primary key, pname
varchar(10),color varchar(10));

6. Create table SP which has the following


attributes
(sno, pnoqty)
Where combination of (sno, pno) is primary
key, also sno and
pno are foreign keys ans:
create table SP27
(snonumber(10) references S27(sno) ,pno
number(10) references P27(pno), constraints
primaryc6 primary key(sno,pno));

7. Create table dept which has the following


attributes
(department table)
(deptno, dname)
Where deptno is primary key, dname in (Acc,
comp, elect)
ans:
create table dept27
(deptnonumber(9) primary key,dname
varchar(25) check(dname in
('Acc','comp','elect')));
8. Create table emp which has the following
attributes (employee
table)
(@empno, ename, job, sal, deptno)
Where empno is primary key, ename is
unique, job in (Prof, AP,
and Lect), sal is not NULL, and deptno is
foreign key
ans:
create table employee_27
(enamevarchar(25)constraint uniquec8
unique
,empno number(6)constraint primaryc8
primary key,
job varchar(25) check (job
in('prof','Assistprof','lect')),sal
number(9)constraint notc8 not null,deptno
number(10) references dept27(deptno));

Potrebbero piacerti anche