DBMS Lab Manual Exp 3,4 & 5
DBMS Lab Manual Exp 3,4 & 5
Experiment -3
Aim- Write a SQL statement for implementing ALTER, UPDATE and DELETE.
Database Language: Database languages are used to read, update and store data in a database.
Read, Update, Manipulate, and Store data in a database using Database Languages. There are four
types of DBMS language:
1. DDL (Data Definition Language)
2. DML (Data Manipulation Language)
3. DCL (Data Control Language)
4. TCL (Transaction Control Language)
DDL (Data Definition language) - DDL is used when we need to create database and tables, alter them,
drop them and rename the table.
TRUNCATE student;
DML (Data Manipulation Language) - DML language is used to manipulate the database like
inserting data, updating table, retrieving record from a table .
DCL (Data Control Language) : Grant privilege to a user using the GRANT statement. revoke the
privilege using the REVOKE statement.
TCL (Transaction Control Language):Manage transactions in the Database using the Transaction
Control Language:
START TRANSACTION,
INSERT INTO student (name, lastname) VALUES ('Dia', 'Shivi),
COMMIT,
START TRANSACTION,
INSERTINTO student (name, lastname) VALUES ('Dia', 'Shivi);
ROLLBACK;
17
Global Institute of Technology
Department of Computer Science & Engineering
SELECT COMMAND
b) Using select *
Syntax:
Select * from tablename;
Ex:
Select * from emp;
Syntax:
Select distinct <col> from <tablename>;
Ex:
Select distinct ename from emp;
18
Global Institute of Technology
Department of Computer Science & Engineering
VIVA QUESTIONS
DDL: DDL stands for Data Definition Language. DDL is used to create and modify the structure of
database objects.
Examples: CREATE, ALTER, DROP statements.
DCL: DCL stands for Data Control Language. DCL is used to create roles, grant and revoke
permissions, establish referential integrity etc.
Examples: GRANT, REVOKE statements
TCL: TCL stands for Transactional Control Language. TCL is used to manage transactions within a
database.
Examples: COMMIT, ROLLBACK statements.
19
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
Experiment-4
Aim- Write the query for implementing the following functions: MAX (),
MIN(), AVG () and COUNT ().
Aggregate Functions: Aggregate functions perform a calculation on a set of rows and return
a single row. The result of an aggregate function is a single value.
These functions are called aggregate functions because they operate on the aggregate of tuples.
You can use aggregate functions as expressions only in the following clauses i.e., SELECT
clause, HAVING clause. There are five aggregate functions:
AVG(): The AVG() function allows you to calculate the average value of a numeric column.
syntax : AVG(expression)
Output :
AVERAGE SAL
22000.0000
COUNT(): The COUNT() function returns the total number of values/rows in the specified field.
Syntax: COUNT(expression)
Output:
count(*)
6
20
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
Department
MAX() : The MAX() function returns the maximum value from the specified table field.
syntax : MAX(expression)
Output :
MAX(Salary
)
30000
MIN(): The MIN() function returns the minimum value in the specified table field.
syntax : MIN(expression)
Output :
MIN(Salary)
SUM(): SUM() function returns the sum of all the values in the specified column. SUM() works
on numeric fields only. Null values are excluded from the result returned.
21
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
Output:
Total Salary
132000
VIVA QUESTIONS:
22
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
Experiment-5
Aim-Perform the following operation for demonstrating the insertion, updation and deletion.
INSERTION Query
Syntax : INSERT INTO table(column1, column2, ...) VALUES (value1, value2, ...);
Example :
Output :
B
101 Alia CSE 9876540010
Example :
23
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
Output:
UPDATION Query :
Output :
Example :
UPDATE college SET NAME = 'Atulya', DEPT = 'ECE' WHERE ROLL_NO = 105;
24
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
DELETION Query :
Example :
Select*from college;
Output :
25
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
Output :
ALTER : ALTER TABLE is used to add, delete/drop or modify columns in the existing table. It is
also used to add and drop various constraints on the existing table.
26
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
Example :
Output :
VIVA QUESTION
27
Global Institute of Technology
DEPARTMENT OF COMPUTER SCIENCE ENGINEERING
28