DBMS

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

DATABASE MANAGEMENT SYSTEM

PRACTICAL FILE
PRACTICAL NO_1: Create a table named uim_employee having attributes such as:
Employee id, Employee name, Employee’s department number, Employee’s date of joining,
Employee’s salary, Employee’s email and Employee’s contact number.
Consider the following table:
Attribute Datatype Size
employee_id Varchar2 10
employee_name Char 25
employee_department_no Number 03
employee_date_of_joining Date -
employee_salary Number 8,2
employee_email_id Varchar2 30
employee_contact_no Number 12
Note: Insert department number values as 111, 222, 333, 444, …. etc.
Note: Insert employee id values as UU1001, UU1002, UU1003, UU1004, …. etc.
Write SQL queries to:
i. Insert at least 10 tuples in table.
ii. Display employee’s complete details including employee_id, employee_name,
employee_department_no, employee_date_of_joining, employee_salary,
employee_email_id, and employee_contact_no.
iii. Display employee’s complete details including employee_id, employee_name,
employee_department_no, employee_date_of_joining, employee_salary,
employee_email_id, and employee_contact_no who work in department number 444.
iv. Display employee_id, employee_name, employee_date_of_joining who work in
department number 222.
v. Delete the employee’s details having employee_id as UU1003.
vi. Update employee_contact_no to 9592929295 having employee_id as UU1007.

Solution:
i) Query for creating table.
create table uim_employee(
employee_id varchar(10),
employee_name char(25),
employee_department_no int(03),
employee_date_of_joining date,
employee_salary int(20),
employee_email_id varchar(30),
employee_contact_no int(12));

Query for inserting the value in the table.


insert into uim_employee values(
'UU1001','DIKSHANT PANTHRI','111','2023-05-04','60000','dikshant@gmail.com',
'989720');
'UU1002','DIWAKAR GAUTAM','222','2023-06-04','30000','diwakar@gmail.com',
'899720');
'UU1003','MANISH BISHT','333','2023-03-04','35000','manish@gmail.com', '884730');
'UU1004','SHEKHAR SUMAN','444','2023-02-04','40000','shekhar@gmail.com', '923843');
'UU1005','HIMANSHU LAKHCHOURA','555','2023-07-04','45000','himanshu@gmail.com',
'836473');
'UU1006','AMISHA RANA','666','2023-09-04','55000','amisha@gmail.com', '536743');
'UU1007','LAVANYA RAWAT','777','2023-08-04','50000','lavanya@gmail.com', '276433');
'UU1008','ANUSHKA SHARMA','888','2023-05-14','25000','anushka@gmail.com',
'764373');
'UU1009','SRISHTI MISHRA','991','2023-03-20','20000','srishti@gmail.com', '754733');
'UU1010','SHAGUN VERMA','999','2023-06-24','65000','shagun@gmail.com', '764733');

ii) select *from uim_employee;


iii) select *from uim_employee WHERE employee_department_no='444';

iv) select employee_id, employee_name, employee_date_of_joining FROM uim_employee


WHERE employee_department_no ='222';

v) DELETE FROM uim_employee WHERE employee_id ='UU1003';

vi) UPDATE uim_employee SET employee_contact_no='959929' WHERE


employee_id='UU1007';
PRACTICAL NO_2: Implement DDL and DML on the uim_employee table. Consider the
following employee table:
Attribute Datatype Size
employee_id Varchar2 10
employee_name Char 25
employee_department_no Number 03
employee_date_of_joining Date -
employee_salary Number 8,2
employee_email_id Varchar2 30
employee_contact_no Number 12

i. Add a new column named employee_address having data type as varchar2, size 30 in
the uim_employee table.
ii. Update the addresses of existing uim_employees in the table.
iii. Drop the column named employee_date_of_joining from the table.
iv. Modify the size of the column named employee_contact_no to 14.
v. Rename the table to uim_employee_details from the table name uim_employee.
vi. Truncate as the records from the uim_employee_details table.
vii. Drop the table named uim_employee_details.
Solution:
i) ALTER TABLE uim_employee ADD employee_address varchar(30);

ii) UPDATE uim_employee SET employee_address ='DEHRADUN';

iii) ALTER TABLE uim_employee DROP COLUMN employee_date_of_joining;

iv) ALTER TABLE uim_employee MODIFY employee_contact_no int(14);


v) ALTER TABLE uim_employee RENAME TO uim_employee_details;

vi) TRUNCATE TABLE uim_employee_details;

vii) DROP TABLE uim_employee_details;

PRACTICAL NO_3: Implementation of keys and constraints concept. Create a table named
uim_student having attributes such as: student's roll number, student's name, student's date of
birth, student's course, student's house address, student's contact number, student's aadhaar
number. The attribute named: student_roll_no has a PRIMARY KEY constraint, student_name
has NOT NULL constraint, student_aadhaar_no as UNIQUE constraint.
Consider the following table:
Attribute Datatype Size Constraint
student_roll_no Number 3 PRIMARY KEY
student_name Char 25 NOT NULL
student_date_of_birth Date - -
student_course Varchar 15 -
student_address Varchar2 30 -
student_contact_no Number 10 -
student_aadhaar_no Number 12 UNIQUE

i. Describe the structure of uim_student table.


ii. Insert few tuples in the table.
iii. Examine the error message by inserting same student_roll_no values for two rows.
Write the error message and reason.
iv. Examine the error message by NOT inserting student_name value in a row in the table.
Write the error message and reason.
v. Examine the error message by inserting same student_aadhaar_no values for two rows.
Write the error message and reason.
Solution:
Query for creating table.
create table uim_student(
student_roll_no int PRIMARY KEY,
student_name varchar(20) NOT NULL,
student_date_of_birth date,
student_course varchar(20),
student_address varchar(30),
student_contact_no int(20),
student_aadhaar_no int(30));

i) desc uim_student;

ii) Insert into uim_student values("111","Manish Bisht","2005-12-


25","BSC","HARIDWAR","989720", "841631486");
Insert into uim_student values("112","Shekhar","2005-03-
25","BSC","Haridwar","934720", "848463546");
Insert into uim_student values("113","Himanshu Lakhchoura","2005-06-
12","BSC","Kanpur","848720", "873625148");
Insert into uim_student values("114","Amisha Rana","2007-06-
12","BSC","Dehradun","748720", "878254728");
Insert into uim_student values("115","Newu Newu","2007-04-
22","LLB","Dehradun","763420", "962537328");
iii) INSERT INTO uim_student VALUES ("111","Alok Gupta","2009-04-12","B-
Tech","Agra","898720","78631486");

iv) INSERT INTO


uim_student(student_roll_no,student_date_of_birth,student_course,student_addres
s,student_contact_no,student_aadhaar_no) VALUES ("444","2004-03-
24","BCA","DEHRADUN","951984", "65483148");

v) INSERT INTO uim_student VALUES ("444","ADARSH","2002-08-


05","BCA","PREMNAGAR","498563","962537328");

PRACTICAL NO_4: Implementation of Foreign key concept using two tables named:
uim_employee and uim_department. The employee table has employee’s id, employee’s name
and employee’s department number. The department has the department number, department
name and department location.
Consider the following two tables:

Table name: uim_employee Table name: uim_department


Data Data
Attribute Size Constraint Attribute Size Constraint
type type
PRIMARY
employee_id Char 8 - department_no Number 3 KEY
employee_name department_name
Varchar2 20 - Char 15 -
employee_departm FOREIGN department_locat
Number 3 Varchar2 20 -
ent_no KEY ion

i. Display the structure of uim_employee table.


ii. Display the structure of uim_department table.
iii. Insert at least three department details in the uim_department table.
iv. Display the data of uim_department table.
v. Insert employee's details working in the corresponding departments as in the
uim_department table.
vi. Display the data of uim_department table.
vii. Examine the error message by inserting a value in employee_department_no which is
NOT there in uim_department table's department_no. Write the error message and
reason.
viii. Delete any department number from the uim_department table and examine its effects
in uim_employee table.
Solution:
Query for creating tables.
CREATE TABLE uim_departments (department_no INT (3), department_name CHAR (15),
department_location VARCHAR (20), PRIMARY KEY (department_no) );

CREATE TABLE uim_employees (employee_id CHAR (8), employee_name VARCHAR


(20), employee_department_no INT (3), FOREIGN KEY (employee_department_no)
REFERENCES uim_departments (department_no) );
i) desc uim_employees;
ii) desc uim_departments;
iii) INSERT INTO uim_departments VALUES (101, "BCA", "Dehradun"), (102,
"MCA", "Dehradun"), (103, "B.Sc.(IT)", "Dehradun");
iv) select *from uim_departments;
v) INSERT INTO uim_employees VALUES ("UU1001", "Arjun Kumar", 101),
("UU1002", "Kavya Negi", 102), ("UU1003", "Shivam Verma", 103);
vi) select *from uim_employees;
vii) INSERT INTO uim_employees (employee_department_no) VALUE (104);
viii) DELETE FROM uim_departments WHERE department_no= "101";
PRACTICAL NO_5: Create a table named employee_contact_details from employee table
by taking the attribute named employee_id.
Consider the table below:

Table name: employee_contact_details


Attribute Datatype Size
employee_id employee_id from employee table
i. Display the contents of employee_contact_details table.
ii. Add a new column employee_contact_no having data type as 12 in
employee_contact_details table.
iii. Display the contents of employee_contact_details table.
iv. Update the contact details of existing employees.
v. Display the updated contents of employee_contact_details table.
Solution:
i) create table employee(emp_id varchar(10),emp_name
char(25),emp_depatment_no varchar(03),emp_date_of_joining date,emp_salary
int(30),emp_email_id varchar(20),emp_contact_no int(12));
ii) insert into employee values('UU101','manish','01','2004-05-
02','3000','manish@gmail.com','87959497'), ('UU102','shekhar','02','2003-02-
03','15000','shekhar@gmail.com','35959497'), ('UU103','himanshu','03','2007-07-
02','1000','himanshu@gmail.com','87959497'), ('UU104','amisha','04','2008-02-
05','12000','amisha@gmail.com','7859497'), ('UU105','aaradhya','05','2006-05-
01','15000','aara@gmail.com','87988497');
iii) select*from employee;
iv) create table emp_contact_details as select emp_id from employee;
v) select*from emp_contact_details;
vi) alter table emp_contact_details add emp_contact_no int(12);
vii) select*from emp_contact_details;
viii) update emp_contact_details set emp_contact_no=”76876785”where
emp_id=”uu101”;
ix) select*from emp_contact_details;
PRACTICAL NO_6: Create a table named uim_book having the attributes related to book id,
book name and book theme. The book_theme attribute can have only two values: IT or MGT
where IT is Information Technology and MGT is Management. Apply CHECK constraint on
the attribute named book_theme.
Consider the table below:

Table name: book


Attribute Datatype Size Constraints
book_id Number 10 PRIMARY KEY
book_name Varchar2 25 NOT NULL
book_theme Char 4 CHECK

i. Describe the structure of uim_book table.


ii. Insert few tuples in the uim_book table.
iii. Display the contents of uim_book table.
iv. Examine the error message by inserting a value other than IT/MGT in column named
book_theme. Write the error message and reason.
Solution:
i) Create table uim_book(book_id int(10),book_name varchar(25)NOT NULL,
book_theme char(4),PRIMARY KEY(book_id),CHECK(book_theme
in('IT','MGT')));
ii) Desc uim_book;
iii) Insert into uim_book values('1001','Manish','MGT');
Insert into uim_book values('1002','Shekhar','IT');
Insert into uim_book values('1003','Himanshu','MGT');
Insert into uim_book values('1004','Amisha','IT');
iv) Select *from uim_book;
v) Insert into uim_book values('1005','Amisha','CHE');

You might also like