Mid Term - (DBMS) Labfile (Sahil Negi)

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

Department of Computer Science and

Technology
MANAV RACHNA UNIVERSITY, FARIDABAD

Subject : Database Management System


(CSH202B)
SUBMITTED TO: Jyoti Ma’am
SUBMITTED BY: Sahil Negi
CLASS: CSE AIML 4B
ROLL NO: 2K21CSUN04058
INDEX
TOPIC DATE
Lab 0 25/01/2023
Lab 1 1/02/2023
Lab 2 8/02/2023
Lab 3&4
Lab 5
LAB 0
CSH202B-T

Q1: Create and display 5 records for students using file operations in C
Q2: Using file operations create, display, modify insert and delete records for employee system
Show database;
Create database project;
Use project;
Create table student(no char(4) PRIMARY KEY, name varchar(30) NOT NULL,class CHAR(10),section
CHAR(1),contact int);
Desc student;

insert into student values(‘5000,’sahil_negi’,’aiml’,’B’,’7048973751’);


insert into student values(‘5001,’kanan_arora’,’aiml’,’B’,’7048973751’);
insert into student values(‘5002,’harsh_yadav’,’aiml’,’B’,’7048973751’);
insert into student values(‘5003,’chirag_garg’,’aiml’,’B’,’7048973751’);
insert into student values(‘5004,’poonam_biswas’,’aiml’,’B’,’7048973751’);

Lab 2
Create table table_name();
Alter table table_name add constraints ch1 constraint_name(attribute);
Insert into table_name(column_name,..) values (‘’,’’,’’);
Select * from table_name;

-Create table empl(emplno char(4) PRIMARY KEY, emplname varchar(30) NOT NULL,class CHAR(10),section
CHAR(1),emplcontact int);

-select * from empl;

-ALTER TABLE empl


ADD Email varchar(255);

-DELETE FROM table_name WHERE condition;


LAB-1 : Creation of Tables

Objective: The student will start making use of DDL commands.

Course Outcome CO1: Students will be able to use DDL – create/alter table statement – to create
relations along with the constraints specified.

Blooms Taxonomy Level: BT2, BT3

1. Client (clno char(3), clname varchar(30), cladd varchar(40))


● PRIMARY KEY- clno
● clname can not be left blank

2. Project (pno char(3), pname varchar(30), pstdate date, clno char(3))


● PRIMARY KEY- pno
● FOREIGN KEY – clno refers to Client relation
● pname can not be left blank

3. Department (dno char(3), dname varchar(20), dloc varchar(20), dhead


char(3))
● PRIMARY KEY – dno
● FOREIGN KEY – dhead refers to eno of Employee relation
● dname can not be left blank
● default dloc is delhi
Lab 2: DDL Commands
________________________________________________________________________
Objective: The student will start making use of DDL commands.

Course Outcome CO1: Students will be able to use DDL – create/alter table statement – to create
relations along with the constraints specified.

Blooms Taxonomy Level: BT2, BT3

4. Employee (eno char(3), ename varchar(20), eadd varchar(30), ephone char(8), esal
int, grade char(1), edoj date, dno char(3), emgrno char(3))

● PRIMARY KEY – eno


● FOREIGN KEY – dno refers to Department relation
● FOREIGN KEY – emgrno refers to eno of Employee relation
● salary can hold values between 1000 and 60000
● grade can be A – if salary less than 20000, B – if salary is between 20000 and
40000, C – if salary is greater than 40000
● doj should be more than 01-jan-1990
● ephone can have unique values only

create table employe ( eno char(3) primary key, ename varchar (20), eadd varchar(30), ephone
char(8) unique, esal int CHECK (esal BETWEEN 1000 and 60000), grade char(1), edoj date CHECK
(edoj >’01-Jan-1990’), dno char(3), FOREIGN KEY (dno) REFERENCES department (dno), emgrno
char(3));

5. Proj_alloc (eno char(3), pno char(3), hrs int)

● PRIMARY KEY – eno, pno


● FOREIGN KEY – eno refers to Employee relation
● FOREIGN KEY – pno refers to Project relation
● hrs can have values more than 2
6. Dependent (eno char(3), dpname varchar(20), dpdob datetime, dprelation varchar(20))

● PRIMARY KEY – eno, dpname


● FOREIGN KEY – eno refers to Employee relation
Dprelation can have only one of the values {son,daughter,father,mother}
Lab 3 & 4: Insertion & Updation of records in Tables
________________________________________________________________________
Objective: The student will start using DML Commands.

Course Outcome CO1: Students will be able to use DML – insert/update table statement – to insert
and update records in existing relations.

Blooms Taxonomy Level: BT2, BT3

A. Insert the records in the following relations:

7. Client (clno char(3), clname varchar(30), cladd varchar(40))

CLNO CLNAME CLADD


-------- ------------- -----------
c01 xyz Delhi
c02 abc Fbd
c03 def Delhi
c04 ghi Ggn
c05 klm Fbd
c06 nop Delhi

8. Project (pno char(3), pname varchar(30), pstdate date, clno char(3))

PNO PNAME PSTDATE CLNO


--------------------- ---------------------------
p01 ab 01-JAN-06 c01
p02 bc 01-FEB-06 c02
p03 cd 20-APR-05 c02
p04 de 01-JAN-04 c03
p05 ef 02-MAY-05 c04
p06 fg 03-FEB-06 c03

9. Department (dno char(3), dname varchar(20), dloc varchar(20), dhead char(3))

DNO DNAME DLOC DHEAD


--------------------------------------------
d01 finance Delhi e01
d02 accounts Fbd e03
d03 personal Ggn e05
d04 marketing Delhi e06
10. Employee (eno char(3), ename varchar(20), eadd varchar(30), ephone char(8), esal
int, grade char(1), edoj date, dno char(3), emgrno char(3))

ENO ENAME EADD EPHONE ESAL GRADE EDOJ DNO EMGRNO


------------- --------------------------------------------------
e01 a Delhi 123453 60000 C 01-JAN-06 d01
e02 b Ggn 231456 20000 B 02-JAN-06 d01 e01
e03 c Fbd 341566 15000 A 08-FEB-05 d02 e02
e04 d Fbd 789012 5000 A 03-JUN-04 d03 e03
e05 e Ggn 345234 6000 A 03-AUG-04 d04 e07
e06 f Delhi 123876 25000 B 03-MAR-05 d03
e07 g Fbd 785634 9000 A 08-MAR-06 d04 e08
e08 h Ggn 895634 18000 A 02-JAN-06 d02
11. Proj_alloc (eno char(3), pno char(3), hrs int)

ENO PNO HRS


----------------
e01 p01 4
e02 p02 6
e02 p03 3
e03 p03 2
e04 p02 8
e06 p01 9
e05 p02 10
e05 p03 20
e07 p05 4
e08 p05 6
e08 p06 8
e04 p03 7

12. Dependent (eno char(3), dpname varchar(20), dpdob date, dprelation varchar(20))

ENO DPNAME DPDOB DPRELATION


---------------------------------------------
e02 ab 01-MAR-65 father
e02 bc 02-AUG-80 brother
e03 dc 02-JUL-89 son
e03 bc 02-JUL-89 daughter
e05 ef 06-JAN-60 mother
e06 fg 07-JUL-50 daughter

B. Update the following information in the relations:

1. Update the salary of employee e06 by increasing it by 10%.


2. Update the dependent relationship of e03 employee with dependent named fg.
3. Update the location of department no d04 to Ggn.
4. Update the hours allocated for employee e07 for project p05 to 6 hrs.
5. Update the name of project no p06 to gh.
6. Update the client address of client no c06 to Ggn.
Lab 5: Retrieval of records from single table
________________________________________________________________________
Objective: The student will understand the concept of DML statements.

Course Outcome CO1: Students will be able to use select statement to retrieve rows from a single
table. (using relational and logical operators, renaming of attributes, order by, like, between etc.)

Blooms Taxonomy Level: BT1, BT2. BT3

1. Retrieve employee name, employee salary and date of joining for the employees working for
department no. ‘D02’.

2. Find the complete details of the projects ordered by client no ‘C02’.


3. Find the dependent name, dependent relation and dependent date of birth for employee no
‘E08’.
4. Retrieve the employee name and employee salary for the employees whose department is D01
or have salary more than 20000.
5. Retrieve the employee name and phone number for the employees whose address contains
Ggn or Fbd and have grade B.
6. Find the employee numbers along with the project numbers for employees who working on a
project between 6 to 10 hrs.
7. Find the employee name, department number and salary they draw in increasing order of
department number and decreasing order of salary.
8. Find the employee names and their address for the employees who do not have any manager.
9. Find the client number who have ordered projects which have ‘e’ in their name.
10. Find the department names and their corresponding location for the departments having head
other than e03 and e05.

You might also like