Uploaded by cisoyij960

DBMS File - FInal

advertisement
Panipat Institute of Engineering & Technology
Samalkha
Computer Science & Engineering Department
Practical File of Database Management Systems Lab
Code -
Submitted to: Ms.Richa Grover
Assistant Professor
CSE Department
Affiliated to
Submitted by: Name
Roll No.
CSE 2nd Year
Section – F
Cybersecurity
Practical No. 1
Problem Statement: Create a database and write the programs to carry out the
following operation:
 Add, Delete and modify a record in the database.
 Generate queries
 Data Operations
 List all the records of database in ascending order
Table Used:
create table college (C_ID number(3), S_NAME char(20), Gender char(1), Age nummber(2),Course char(6))
insert into college values('319', 'Mudit Gupta', 'M', '19', 'CSE')
insert into college values('123', 'Simran', 'F', '19', 'IT')
insert into college values('295', 'Nazim Mazumdar', 'M', '21', 'MBA')
insert into college values('294', 'John L Songate', 'M', '18', 'IT')
insert into college values('319', 'Rishabh Varshney', 'M', '19', 'CSE')
insert into college values('302', 'Syed Saquib', 'M', '18', 'CSE')
insert into college values('456', 'Yashika Tonk', 'F', '20', 'ECE')
Add, Delete and modify a record in the database.
Command: INSERT
Syntaxinsert into <table name> values (<expression1>,<expression2>)
Exampleinsert into College values(‘789’,’Lucy David’,’F’,’21’,’MCA’ )
Output-
Command: UPDATE
Syntaxupdate tablename set field=values where condition
Exampleupdate College set Course = ‘MCA’ where C_ID = ‘789’
Output-
After updating-
Command: DELETE
SyntaxDelete from <table-name>
Exampledelete from College where Course = ‘MCA’
Output-
After Deletion-
Generate queries
select * from College
Output-
select S_Name from College where C_Id BETWEEN 1000 and 1003
Output-
Data Operations
Command- AND
select S_Name, Course from College where C_ID = 319 and Age = 19
Output-
Command - OR
select S_Name from College where C_ID = 1000 or Age = 19
Output-
Command – NOT
select S_Name from College where NOT Age = 20
Output-
\
List all the records of database in ascending order
Command – ORDER BY
select * from College order by AGE
Output-
Practical No. 2
Problem Statement: To perform various integrity constraints on relational database.
Primary Key Constraints
create table mg(S# number(3) primary key, Name char(20), Age number(2), check(age>18));
select * from mg;
Output:
insert into mg values('', 'Kimetsu', 20);
Output:
insert into mg values('319', 'Yaibo', 20);
Output:
Domain Constraints
create table mg(S# number(3) primary key, Name char(20), Age number(2), check(age>18));
select * from mg;
Output:
insert into mg values('319', 'Lucky', 16);
Output:
Practical No. 3
Problem Statement: Create a database and perform the following operations:1. Arithmetic and Relational Operations
2. Group By and Having clause
3. Like predicate for pattern matching in database
Table creation:
create table Employee(E_ID number(5) primary key, Name char(20), Age number(2), Salary
number(6))
insert into Employee values('319', 'Mudit Gupta', '19', '45000')
insert into Employee values('123', 'Alex', '19', '40000')
insert into Employee values('321', 'James', '20', '35000')
insert into Employee values('456', 'Lucy', '21', '37000')
insert into Employee values('654', 'Peter', '20', '30000')
insert into Employee values('789', 'Parle', '21', '33000')
select * from Employee
Output-
Arithmetic OperationsAdd Operator (+)
Exampleupdate Employee set Salary = Salary + 500
select * from Employee
Output-
Subtract Operator (-)
Exampleupdate Employee set Salary = Salary - 400
select * from Employee
Output-
Multiply Operator (*)
Example-
update Employee set Salary = Salary * 3
select * from Employee
Output-
Divide Operator (/)
Exampleupdate Employee set Salary = Salary / 2
select * from Employee
Output-
Relational OperationsEqual Operator (=)
Exampleselect * from Employee where Salary = 45150
Output-
Less than Operator (<)
Exampleselect * from Employee where Salary < 55000
Output-
Greater than Operator (>)
Exampleselect * from Employee where Salary > 55000
Output-
Greater than or equal to (>=)
Exampleselect * from Employee where Salary >= 50000
Output-
Less than or equal to (<=)
Exampleselect * from Employee where Salary <= 60000
Output-
Not equal to (<>)
Exampleselect * from Employee where Salary <> 49650
Output-
Group By ClauseExampleselect count(Name), Age from Employee group by Age
Output-
Having ClauseExampleselect count(Name), Age from Employee group by Age having count(E_ID)>=2
Output-
Like predicate for pattern matching in databaseExampleselect Name from Employee where Name like 'P%'
Output-
Practical No. 4
Problem Statement: Create a view to display details of employees working on more
than one project.
Table Creation:
select * from Company
select * from Project
Command:
create view MultiProj as select Company.Name, Project.Project_Name from Company inner join
project on company.ssn = project.ssn where project.ssn in ( select SSN from project group by SSN
having Count(SSN)>1)
Output:
select * from MultiProj
Output:
Practical No. 5
Problem Statement: Create a view to display details of employees not working on any
project.
select * from Company
select * from Project
Command:
create view NoProj as select Company.SSN ,Company.Name from Company left join Project on
company.ssn = project.ssn where project.ssn is NULL order by Company.ssn
Output:
Command:
select * from NoProj
Practical No. 6
Problem Statement: Using two tables create a view which shall perform natural join,
equi join, outer joins.
select * from emp
Output:
select * from dept
Output:
Full Join:
Select emp.eid , emp.Name , emp.Salary , emp.DID, Dept.DID , Dept.D_Name from EMP full join Dept on
emp.DID = Dept.DID
Output:
Inner Join:
Select emp.eid , emp.Name ,emp.Salary, emp.DID, Dept.DID ,Dept.D_Name from emp inner join Dept on
emp.DID = Dept.DID
Output:
Left Join:
Select emp.eid , emp.Name ,emp.Salary, emp.DID, Dept.DID ,Dept.D_Name from emp left join Dept on
emp.DID = Dept.DID
Output:
Right Join:
Select emp.eid , emp.Name ,emp.Salary, emp.DID, Dept.DID ,Dept.D_Name from emp right join Dept on
emp.DID = Dept.DID
Output:
Download