Alok Dbms

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 36

1

DATABASE MANAGEMENT SYSTEM


PRACTICAL FILE
PRACTICAL NO_01:
Create a table named uscs_emp 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.
Query:
create table uscs_emp(
emp_id varchar(20),
emp_name varchar(20),
emp_dep_no int(20),
emp_date_join date,
emp_salary int(20),
email_id varchar(20),
contact int (20));
Output

 Insert at least 10 tuples in table


Query:
For inserting the value in the table.
insert into uscs_emp values (
'UU1001','DIKSHANT PANTHRI','111','2023-05-04', 60000, ‘dikshant@gmail.com', '989720');
'UU1002','DIWAKAR GAUTAM','222','2022-05-14', 30000, ‘died@gmail.com','899720’);
'UU1007','LAVANYA RAWAT','777','2004-07-18','40000’, ‘lavanya@gmail.com','358620');
'UU1008','ANUSHKA SHARMA','888','2022-12-27','35000’, ‘anushka@gmail.com','989720'
'UU1009','SRISHTI MISHRA','991','2001-01-31','55000’, ‘srishti@gmail.com','989720');
'UU1010','SHAGUN VERMA','999','2008-07-23','45000’, ‘shagun@gmail.com','648620');
1|Page
2

Output

 Display employee’s complete details including emp_id, emp_name, emp_dep_no,


emp_date_join, emp_salary, email_id, and contact.

Query:
Select * from uscs_emp;

Output

 Display employee’s complete details including emp_id, emp_name, emp_dep,


emp_date_join, emp_salary, emp_email_id, and emp_contact_no who work in
department number 444.
 Query:
SELECT * FROM uscs_emp WHERE emp_dep_no = ‘444’;
Output

2|Page
3

 Display emp_id, emp_name, emp_date_join who work in department number 333.

Query:
SELECT emp_id, emp_name, emp_date_join FROM uscs_emp WHERE emp_dept_no = '333';

Output

 Delete the employee’s details having emp_id as UU1003.

Query:
DELETE FROM uscs_emp WHERE emp_id = 'UU1003'

Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


4

 Update contact_no to 9592929295 having emp_id as UU1007.

Query:
UPDATE uscs_emp SET contact ='95929'
WHERE emp_id = 'UU1007';
Output

FINAL TABLE:

Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


5

PRACTICAL NO-02:
Implement DDL and DML on the uim_employee table. Consider the following employee
table:
Attribute Data type Size
emp_id Varchar2 10
emp_name Char 25
emp_dept_no Number 03
emp_date _join Date -
emp_salary Number 8,2
email_id Varchar2 30
contact_no Number 12

Query:
create table uim_emp(
emp_id varchar(20),
emp_name varchar(20),
emp_dep_no int,
emp_date_join date,
emp_salary int,
email_id varchar(20),
contact int);
Output

 Add a new column named emp_address having data type as varchar2, size 30 in the
uim_employee table.

Query:
ALTER TABLE uim_emp
ADD emp_address VARCHAR(30);

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


6

Output

 Update the addresses of existing uim_emp in the table.

Query:

UPDATE uim_emp
SET emp_address = 'DEHRADUN';
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


7

 Drop the column named emp_date_join from the table.

Query: ALTER TABLE uim_emp

DROP COLUMN emp_date_join;

Output

 Modify the size of the column named emp_contact_no to 14.

Query:
ALTER TABLE uim_emp
MODIFY contact int(14);
Output

 Rename the table to emp_details from the table name uim_employee.

Query:
ALTER TABLE uim_emp
RENAME TO emp_details;
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


8

 Truncate as the records from the emp_details table.

Query:
TRUNCATE TABLE emp_details;

Output

 Drop the table named emp_details.

Query:
DROP TABLE emp_details;
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


9

PRACTICAL NO_3:

Implement 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 Data type 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

Query:
create table uim_student(
rollno int primary key,
s_name varchar(20) not null,
date_of_birth date,
s_course varchar(20),
s_address varchar(30),
s_contact int(20),
s_aadhaar int(30));
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


10

 Describe the structure of uim_student table.

Query:
DESCRIBE uim_student;
Output

 Insert few tuples in the table.

Query:
INSERT INTO uim_student
values("111","Yashank Gupta","2004-05-24","BCA","HARIDWAR","989720", "841631486");

INSERT INTO uim_student


values ("112","Yash Gupta","2004-05-24","BCA","Farrukhabad","934720", "841631486");

INSERT INTO uim_student


values("113","Vashu Gupta","2006-07-31","BSC", “Farrukhabad","848720", "861631486");

INSERT INTO uim_student


values("114","Aryan Gupta","2008-12-29","MSC","Agar","784720", "908631486");

INSERT INTO uim_student


values("115","Kartik Gupta","2003-12-30","B-Tech","Kanpur","468720", "786314864");
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


11

 Examine the error message by inserting same student_roll_no values for two rows. Write
the error message and reason.

Query:
INSERT INTO uim_student VALUES ("111","Alok Gupta","2009-04-12","B-
Tech","Landon","898720","78631486");
Output

 Examine the error message by NOT inserting student_name value in a row in the table.
Write the error message and reason.

Query:
INSERT INTO uim_student (roll no, date_of_birth, s_course, s_address, s_contact, s_aadhaar)
VALUES ("444","2004-03-24","BCA","DEHRADUN","951984", "65483148");
Output

 Examine the error message by inserting same student s_aadhaar values for two rows.
Write the error message and reason
Name -Alok singh rana ROLL NO-2209000045 BCA 3rd ,” E”
12

Query:
INSERT INTO uim_student
VALUES ("444","ADARSH","2002-08-05","BCA","PREMNAGAR","498563",
“5685650'");
Output

FINAL TABLE

Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd ,” E”


13

PRACTICAL NO_4:
Implement of foreign key concept using two tables named: uscs_emp and uscs_dep. The
employee has employee’s id, employee’s name, employee’s department number. The
department table has department name and department location.
Consider the following two table:

Table name: uscs_emp Table name: uscs_dep


Attribute Data Size Constraint Attribute Data Size Constraint
Type Type
emp_id Int 8 - dep_id Char 8 -
emp_name Varchar 20 - dep_name Varchar 20 -
emp_dep Number 3 FOREIGN dep_loc Numbe 3 FOREIGN
KEY r KEY

Query:
CREATE TABLE uscs_dep(
dep_id CHAR(8),
dep_name VARCHAR(20),
dep_loc INT(3),
PRIMARY KEY (dep_id));

CREATE TABLE uscs_emp2(


emp_id VARCHAR(20),
emp_name VARCHAR(20),
emp_dep INT(3),
FOREIGN KEY (emp_dep) REFERENCES uscs_dep(dep_loc));

Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd ,” E”


14

 Display the structure of uscs_emp2 table.

Query:
DESCRIBE uscs_emp2;
Output

 Display the structure of uscs_dep table.

Query:
DESCRIBE uscs_dep;
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


15

 Insert at least three department details in uscs_dep table.

Query:
INSERT INTO uscs_dep
VALUES ("aaaa","CODEX","111");

INSERT INTO uscs_dep


VALUES ("bbbb","CULTURAL","222");

INSERT INTO uscs_dep


VALUES (“ccccc","SPORTS","333");
Output

 Display the data of uscs_dep table.

Query:
SELECT * FROM uscs_dep;
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


16

 Insert employee’s details working in the corresponding department as in the uscs_dep


table.

Query:
INSERT INTO uscs_emp2(emp_id, emp_name, emp_dep) VALUES
("xxxx","SWATI SINGH","111"),
("yyyy","MANISHA KHANDUJA","222"),
("zzzz","PREVEEN","333);
Output

 Display the data of uscs_emp2 table.

Query:
SELECT * FROM uscs_emp2;
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


17

 Examine the error message by inserting a value in emp_dep which is NOT there in
uscs_dep table’s departments. Write the error message and reason.

Query:
INSERT INTO emp_dep (emp_name, dep_id)
VALUES ("John Doe", "NonexistentDept");
Output

 Delete any department number from uscs_dep table and examine its effects in uscs_emp2
table.

Query:
DELETE FROM uscs_dep WHERE dep_loc = '111';
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


18

Query:
DELETE FROM uscs_emp2 WHERE emp_dep = '111';
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


19

PRACTICAL NO-05:
Create a table named employee_contact_details from employee table by taking the attribute
named: employee_id. Perform Add, Update and Display operations.
Query:
create table employee
(
emp_id int,
emp_name varchar (32),
emp_age int
);
desc employee;
insert into employee values(101,'Aman',20);
insert into employee values(103,'Ronit',19);
 Display data of employee table
Query: -
Select * from employee;
Output

 Create a table named employee_contact_details from employee table by taking the


attribute named: employee_id

Query: -
Create table employee_contact_details select emp_id from employee;

 Add a column name emp_contact


Query: -

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


20

 Update Contact number to emp_contact


Query: -
update emp_contact_details set emp_contacts = 673217 where emp_id = 101;

 Display emp_contact_details
Query: -
Select * from emp_contact_details;
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


21

PRACTICAL 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.

Query: -
CREATE TABLE uim_book (
book_id INT PRIMARY KEY,
book_name VARCHAR(255),
book_theme VARCHAR(3) CHECK (book_theme IN ('IT', 'MGT'))
);

 Insert Data into uim_book

Query: -
insert into uim_book values (102,"Principles of Management”, MGT');

 Apply CHECK constraint on the attribute named book_theme.

Query: -
insert into uim_book values (103,"Health and Care’s');

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


22

PRACTICAL 8: -

The data in the table can be grouped based on certain attributes. Consider the book table
having attributes Aboukir, book name, book theme and book_price. Perform operations on
Group. Note: the book theme can either be 'it' or 'mgt'

Query: -
drop database Practical_08;
create database practical_08;
use practical_08;
create table uscs_book (
book_id varchar (10) primary key,
book_name varchar (25) not null,
book_theme varchar (4) check (book_theme in ("cs", "it"))
);
Output

Query: -
select * from uscs_book;
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


23

Query: -
alter table uscs_book add book_prise decimal (7);

Query: -
select * from uscs_book;
Output

Query: -
update uscs_book
Query: -
insert into uscs_book values ("UU100", "PYTHON", "cs", 285)
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


24

Query: -
select * from uscs_book;
Output

9
Query: -
select sum(book_prise) as total_book_prise from uscs_book;
Output

Query: -
select max(book_prise) as max_book_prise from uscs_book;
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


25

PRACTICAL 9: -
There are numerous aggregate functions that can be performed on table(s). Consider the
attributes in the employee table as: employees id, employees name, employees
department number, employees’ designation, employees date of joining, employee’s
salary, employees email id, employees contact no and employees Aadhaar number.
Create
Query: -
database practical_09;
use practical_09;
select * from uim_employee;
drop database practical_09;
create table uu_employee (
employee_id varchar (30) primary key,
employee_name char (25) not null,
employee_department_no int (3) not null,
employee designation varchar (15) not null,
employee_date_of_joining date not null,
employee_salary float (8) not null,
employee_email_id varchar (30) not null,
employee_contact_no varchar (12) not null,
employee_aadhar_no varchar (12) unique
);
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


26

 Inserting a value
Query: -

Query: -
select * from uu_employee;
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


27

Query: -
select sum(employee_salary) as total _salaries from uu_employee;
Output

Query: -
select sum(employee_salary) as total_salaries from uu_employee where employee_
department _no= 222;
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


28

PRACTICAL 10: -
Create uim_employee table.
i) Count the number of employees in the uim_employee table.
ii) Display the maximum salary of employees having employee designation as assistant
prof.
iii) Display the minimum salary of employees having employee designation as Professor
iv) Calculate the average of salaries of all the employees

Query:
create database Practical_10;
use Practical_10;
drop database Practical_10;
create table uim_employee (
employee_id varchar (30) primary key,
employee_name char (25) not null,
employee_department_no int (3) not null,
employee designation varchar (30) not null,
employee salary float (8) not null
);
Output

Query:
insert into uim_employee values

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


29

Query:
select * from uim_employee;
Output

Query:
select count (*) as total employees from uim_employee;
Output

Query:
select max (employee salary) as max_salary from uim_employee where employee
designation = "Assistant Professor";
Output

Query:
select min (employee salary) as max_salary from uim_employee where employee
designation = "Professor";
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


30

PRACTICAL 11: -

Implement the single-row character function on the customer table. The customer table as
attributes related to customers id, customers first name, customers last name, customers
contact number, customers house number, customers street of address, customers city of
address, customers state of address and customers email id
Query:
create table customer (
customer varchar (10) primary key,
customer_first_name char (25) not null,
customer_last_name char (25),
customer_contact_no varchar (03) not null,
customer_house_no varchar (03),
customer_house_street varchar (15),
customer_house_city varchar (15),
customer_house_state varchar (15),
customer_email_id varchar (20)
);
Output

Query:
insert into customer values("UU1001", "MD", "ALI", "620", "52", "Mainblock", "Ara",
"BIHAR", "md4314674@gmail.com"),
("UU1002", "Lucky", "Kumar", "720", "216", "Railway Station", "ARA", "BIHAR",
"lucy620@gmail.com"),
("UU1003", "Shaddab", "ALAM", "926", "49", "Village", "Gaya", "BIHAR",
"pawan5427@gmail.com");
Query:

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


31

select * from customer;


Output

Query:
select concat (customer_first_name, ' ', customer_last_name) as full_name
from customer
limit 0, 1000;
Output

Query:
select UPPER (customer_first_name) as uppercase_first_name
from customer;
Output

Query:
select
concat (ucase (left (customer_house_city, 1)), lcase (substring (customer_house_city, 2)))
as formatted_city
from customer;
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


32

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


33

PRACTICAL 12: -

Implement the date functions on uu_employee table. Consider the attributes in the
employee table as: employees id, employees name, employees department number,
employees’ designation, employees date of joining, employees salary, employees email
id, employees contact no, employees Aadhaar number and employees date of resigning.

Query:
create database practical_12;
use practical_12;
drop database practical_12;
-- (this is comment) SAIF
create table uu_employee(
employee_id varchar(10) primary key,
employee_name char(25) not null,
employee_department_no int(3) not null,
employee_designation varchar(15) not null,
employee_date_of_joining date not null,
employee_salary float(8) not null,
employee_email_id varchar(30) not null,
employee_contact_no varchar(12) not null,
employee_aadhar_no varchar(12) unique
);
Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


34

Query:
describe uu_employee;
Output

Query:

Query:

Query:

Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


35

Query:

Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”


36

Query:

Output

Name -Alok singh rana ROLL NO-2209000045 BCA 3rd,” E”

You might also like