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

1

Loyola Academy
Degree & PG College
OLD ALWAL,SECUNDERABAD - 500010
[AN AUTONOMOUS DEGREE COLLEGE AFFILIATED TO OSMANIA UNIVERSITY]
‘A college with potential for excellence’ by UGC. Re-accredited with GRADE ‘A’ by NAAC

Department of
B.COM HONOURS

Certificate
This is to Certify that this is a BONAFIDE RECORD of the work done
in the “DATABASE MANAGEMENT SYSTEMS” lab during the 3RD YEAR
/5TH SEMESTER in the academic year
2023-2024.

Name :SAMEER BHERI


Class :DCH
Hall Ticket Number :111721014047

Internal Examiner Principal External Examiner


2
3

INDEX
S.NO CONTENT PAGE DATE SIGN
NO.
1.) Write a query to 5
create a table using
appropriate data
type.

2.) Write a query to insert data into table & 5


display the table.

3.) Write a query to display distinct values or 6


unique values from the table.

4.) 6
Write a query to select or display only
selected column.

5.) Write a query to create a table from another 7


table.

6.) 7
Write a query to create a table from another
table by specifying a condition

7.) Write a query to update all the rows of the 8


table.

8.) 8
Write a query to update selected content in a
table.

9.) Write a query to delete selected rows from a 9


table.

10.) Write a query to Rename a existing table. 9


11.) Write a query to delete a table. 10

SET OPERATIONS
4

12.) Write a query to perform UNION set 11


operation.

13.) Write a query to perform UNION ALL set 12


operation.

14.) Write a query to perform INTERSECT set 12


operation.

AGGREGATE FUNCTIONS
15.) Write a query to perform COUNT aggregate 13
function.

16.) Write a query to perform SUM aggregate 14


function.

17.) Write a query to perform AVERAGE 14


aggregate function.

18.) Write a query to perform MINIMUM 15


aggregate function.

19.) Write a query to perform MAXIMUM 15


aggregate function.

SCALAR OPERATIONS
20.) Write a query to perform UPPERCASE Scalar 16
Function.

21.) Write a query to perform lowercase Scalar 17


Function.

22.) Write a query to perform MD Scalar 17


Function.

23.) Write a query to perform LENGTH Scalar 18


Function.
5

24.) Write a query to perform ROUND Scalar 18


Function.

25.) Write a query to perform FORMAT Scalar 19


Function.

26.) Write a query to perform GETDATE Scalar 19


Function.

CONSTRAINS
27.) 20
Write a query to perform NOT
NULL(under domain constraint) as a
constraint.

28.) 21
Write a query to perform CHECK
(under domain constraint) as a
constraint.

29.) 21
Write a query to perform KEY
constraint

30.) Write a query to perform ENTITY INTEGRITY 22


CONSTRAINT.
JOINS
31.) Write a query to execute INNER JOIN 23

32.) Write a query to execute LEFT JOIN 24

33.) Write a query to execute RIGHT JOIN 24

CREATING TRIGGERS
34.) Write a query to perform TRIGGER. 25

CREATING PROCEDURES
35.) Write a query to perform PROCEDURE. 26
6

1) Write a query to create a table using appropriate


data type.

SQL> create table DCH(ID int primary key not null,Name


char(10),Address char(10),Email char(20));
OUTPUT:

2) Write a query to insert data into table & display the table.
SQL> insert into DCH
values(26,’Swetha’,’Hyd’,’swetha@gmail.com’); SQL> insert into DCH
values(25,’Priya’,’SEC’,’Priya@gmail.com’); SQL> insert into DCH
values(24,’Anjali’,’NZB’,’anjali@gmail.com’); SQL>Select*from DCH;
OUTPUT:
7

3) Write a query to display distinct values or unique values from the table.

SQL>Select distinct(Name) from DCH;


OUTPUT:

4) Write a query to select or display only selected column.

SQL> Select Address from DCH;


OUTPUT:
8

5) Write a query to create a table from another table.


SQL> Select into fee from ACH;
SQL> Select*from ACH;
OUTPUT:

6) Write a query to create a table from another table by specifying a condition


SQL> Select into fee from ACH where ID<25;
SQL> Select*from FEE;

OUTPUT:
9

7) Write a query to update all the rows of the table.


SQL> update DCH set address=’hyd’ where
ID>001; SQL>Select*from DCH;
OUTPUT:

8) Write a query to update selected content in a table.


SQL> Update DCH set Address=’hyd’ where
ID=24; SQL>Select*from DCH;
OUTPUT:
10

9) Write a query to delete selected rows from a table.


SQL> delete from DCH where ID>25;
SQL>Select*from DCH;
OUTPUT:

10) Write a query to Rename a existing table.


SQL> sp_rename
SQL>‘DCH’,’ZCH’;
OUTPUT:
11

11) Write a query to delete a table.


SQL> Drop table NCH;

OUTPUT:

SET OPERATIONS:
To perform set operations, you need two
tables. Table1:
12

Table2

1) Write a query to perform UNION set operation.


SQL> Select*from table1 union select*from table2;
OUTPUT:
13

2) Write a query to perform UNIONALL set operation.


SQL> Select*from table1 union all select*from table2;

OUTPUT:

3) Write a query to perform INTERSECT set operation.


SQL> Select*from table1 intersect select*from table2;

OUTPUT:
14

AGGREGATE FUNCTIONS:
To perform Aggregate functions, you need only one
table. Table1

1) Write a query to perform COUNT aggregate function.


SQL> Select count(*) as ID from table1;

OUTPUT:
15

2) Write a query to perform SUM aggregate function.


SQL> Select SUM(ID) as TOTAL from table1;

OUTPUT:

3) Write a query to perform AVERAGE aggregate function.


SQL>Select avg(ID) as TOTAL from table1;

OUTPUT:
16

4) Write a query to perform MINIMUM aggregate function.


SQL> Select min(ID) from table1;

OUTPUT:

5) Write a query to perform MAXIMUM aggregate function


SQL> Select max(ID) from table1;

OUTPUT:
17

SCALAR OPERATIONS:
To perform SCALAR OPERATIONS, you need only one table.

1) Write a query to perform UPPERCASE Scalar Function.


SQL>Select UPPER(NAME) AS LIST FROM DCH;
OUTPUT:
18

2) Write a query to perform lowercase Scalar Function.


SQL>Select lower(NAME) AS LIST FROM DCH;

OUTPUT:

3) Write a query to perform MID Scalar Function.


SQL>Select SUBSTRING(‘PURVI’,1,5) AS LIST FROM DCH;
OUTPUT:
19

4) Write a query to perform LENGTH Scalar Function.


SQL>Select LEN(NAME) AS LengthofName FROM DCH;

OUTPUT:

5) Write a query to perform ROUND Scalar Function.


SQL>Select ROUND(ID,3) AS LengthofName FROM DCH;
OUTPUT:
20

6) Write a query to perform FORMAT Scalar Function.


SQL>Select FORMAT(ORDERDATE,’YYYY-MM-DD’) AS LengthofName
SQL> FROM ORDER5;
OUTPUT:

7) Write a query to perform GETDATE Scalar Function.


SQL>Select ORDERDATE GETDATES FROM ORDER5;
OUTPUT:
21

CONSTRAINS:
1) Write a query to perform NOT NULL(under domain constraint) as a
constraint.
SQL> Create table QCH(ID int primary key not null,Name char(10) NOT
NULL,Address char(10),Email char(20));
iNSERT INTO QCH VALUES(1,’Anjali’,'HYD','ANJALI@GMAI.COM');
Select*FROM QCH;

OUTPUT 1:

OUTPUT 2:
22

2) Write a query to perform CHECK (under domain constraint) as a


constraint.
SQL> Create table RESULT(StudentID int primary key not null,MID1 int,MID2 int,total int
check(total>70));
OUTPUT:

3)Write a query to perform KEY CONSTRAINT. SQL>


create table DCH(ID int primary key not null,Name
char(10),Address char(10),Email char(20));
OUTPUT:
23

4) Write a query to perform ENTITY INTEGRITY


CONSTRAINT. SQL> create table DCH(ID int primary key not
null,Name char(10),Address char(10),Email char(20));
OUTPUT:

JOINS:
To perform different types of JOINS, you need two tables.
Customer Table:
24

Order Table:

1) Write a query to execute INNER JOIN


SQL> Select CustomerName,city
from customer
Inner join ORDER5 on customer.customerID= Order5.customerID;
OUTPUT:
25

2) Write a query to execute LEFT JOIN.


SQL> SELECT Customer.CustomerName, Order5.OrderID
FROM Customer
LEFT JOIN Order5 ON Customer.CustomerID = Order5.CustomerID
ORDER BY Customer.CustomerName;
OUTPUT:

3) Write a query to execute RIGHT JOIN.


SQL> SELECT Order5.OrderID, Customer.Customername, order5.Orderdate
SQL>FROM order5
SQL>RIGHT JOIN customer ON Order5.customerID = customer.customerID
ORDER BY Order5.OrderID;
OUTPUT:
26

CREATING TRIGGERS:
To perform TRIGGER, you need ONLY ONE table.

1) Write a query to perform TRIGGER.


SQL>Create trigger SAMPLE on
dch
after insert
as
set nocount on
declare @ID INT;
Select @id=i.id FROM
inserted i;
insert into DCHFEE (ID,FEES)
values(@id,500);
OUTPUT:
27

CREATING PRODECURE:
To perform PROCEDURE, you need ONLY ONE
table. CUSTOMER:

1) Write a query to perform a PROCEDURE.


SQL> CREATE PROCEDURE SelectAllCustomers AS
SELECT * FROM Customer
GO;

OUTPUT:
28

THE END
29
30

You might also like