DBMS P-1
DBMS P-1
11723210031
PRACTICAL -1
1
Rudra Saini
11723210031
2
Rudra Saini
11723210031
Syntax:
CREATE TABLE TABLE_NAME (COLUMN_NAMES DATATYPES [ ...]);
DROP: It is used to delete both the structure and record stored in the table.
Syntax:
INSERT INTO TABLE_NAME (col1, col2, col3,.... col N) VALUES (value1, val
ue2, value3, .... valueN);
Pre-Viva questions:
1. What does SQL stand for?
2. What are the applications of SQL in real world?
3. What is the difference between primary key and foreign key?
Post-Viva questions:
1. Explain the different types of numeric data types supported by SQL.
2. Name the string data types available in SQL.
3
Rudra Saini
11723210031
PRACTICAL – 2
AIM- To study Basic SQL commands (create database, create table, use, drop,
insert) and execute the queries using these commands.
COMMANDS-
1. CREATE and USE:
Syntax: Create Database ;
Use <name>;
2. CREATE TABLE:
Syntax: Create table <table_name>(<attribute_name> datatype{e.g. Char(20)},
<name2>datatype,…});
3. INSERT:
Syntax: Insert into <table_name> values (‘data1’,’data2’);
4. SELECT:
Syntax: Select * from <table_name> where <attribute_name>=’data1’;
4
Rudra Saini
11723210031
5. DELETE FROM:
Syntax:
Delete from <table_name> where <attribute_name>=’data1’;
6.DROP:
Syntax:
Drop table <table_name>;
Pre-Viva questions:
1. What is INSERT command?
2. What are the different ways to use INSERT INTO command?
Post-Viva questions:
1. When would you use DROP command in SQL?
2. Difference between DROP and TRUNCATE command.
3. CREATE and DROP commands belong to which category?
5
Rudra Saini
11723210031
PRACTICAL – 3
AIM:- To study the viewing commands (select & update) and execute the queries using these
commands.
6
Rudra Saini
11723210031
2. Update Motorbike
Set model=2024
Where name= “Pulsar RS”;
Output :-
7
Rudra Saini
11723210031
Pre-Viva questions:
1. What is select command used for?
2. How to specify condition with select command?
3. What is update command?
Post-Viva questions:
1. Difference between update and alter command
2. Update and select commands belong to which category?
8
Rudra Saini
11723210031
PRACTICAL – 4
AIM:- To study commands to modify structure of table (alter, delete, add, modify, drop)
and execute the queries using these commands.
Table used to execute commands:
SQL Queries:
1. ALTER TABLE - ADD:
SYNTAX: ALTER TABLE table_name ADD column_name datatype;
OUTPUT:
9
Rudra Saini
11723210031
4. DELETE:
SYNTAX: DELETE from table_name WHERE condition;
OUTPUT:
Result:
All commands are executed successfully.
10
Rudra Saini
11723210031
Pre-Viva questions:
1. What is drop command?
2. What is Alter command used for?
3. Delete and modify commands belong to which category?
Post-Viva questions:
1. How to specify condition with delete command?
2. Difference between drop and delete command?
11
Rudra Saini
11723210031
PRACTICAL – 5
AIM :- To study the commands that involve compound conditions (and ,or ,in, not in,
between , not between , like , not like ) and execute the queries using these commands.
Commands Used:
AND – It is used to filter records based on more than one condition. It displays a
record if all conditions are true.
Syntax- SELECT col1, col2
FROM table_name
WHERE condition1 and condition2.
OR – It displays a record if any of the condition are true.
Syntax—SELECT col1, col2
FROM table name
WHERE condition1 or condition2.
IN – It is used to specify multiple values in a where clause.
Syntax - SELECT column_name
FROM table_name
WHERE column name IN (value1, value2…)
NOT IN – It is used to replace a group of argument using<>(or!=)operator that are
combined with a find .
Syntax- SELECT column_name
FROM table_name
WHERE column name between Value1 and Value2;
BETWEEN – The operator selects values within a given range .
Syntax – SELECT column_name
FROM table_name
WHERE column_name between Value1 AND Value2;
NOT BETWEEN – It is used for getting the values which is outside of the specified
range .
Syntax - SELECT column_name
FROM table_name
WHERE column_name not between Value 1 and Value2;
12
Rudra Saini
11723210031
13
Rudra Saini
11723210031
14
Rudra Saini
11723210031
PRE-VIVA QUESTIONS:
1. Where is AND used for?
2. Difference between IN and NOT IN?
3. In like why we use %?
PRE-VIVA QUESTIONS:
1. When would you use BETWEEN in SQL?
2. What is like and not like?
PRACTICAL – 6
15
Rudra Saini
11723210031
AIM:- To study the aggregate functions (sum, count, max, min, average) and execute the
queries using these commands.
Aggregate Functions:
Functions where the values of multiple rows are grouped together as input based on certain
criteria to form a single value of more significant meaning are known as AGGREGATE
FUNCTIONS.
Table Used :
16
Rudra Saini
11723210031
SQL Queries:-
1) Find the average salary of the employees:
SELECT AVG(Salary) FROM Employee;
OUTPUT:-
17
Rudra Saini
11723210031
5) Print the details of the employee having the minimum gross salary:
SELECT * FROM Employees
WHERE Salary IN (SELECT MIN(Salary) FROM Employees);
OUTPUT:-
PRE-VIVA QUESTIONS:
1. What are aggregate functions in SQL and why are they important in database
management?
2. What is the COUNT function in SQL? How does the COUNT function handle NULL
values?
3. Explain the usage of SUM function in SQL.
POST-VIVA QUESTIONS:
1. Illustrate MAX and MIN functions in SQL.
2. Explain the difference between COUNT(*) and COUNT(column_name) in SQL.
3. When would you use the AVG function in SQL, and what type of columns does it
operate on?
18