100% found this document useful (1 vote)
4K views

DBMS Practical File

The document summarizes 10 practical SQL exercises covering key SQL topics like data definition, data manipulation, logical operators, comparison operators, functions, relational algebra, joins, subqueries, views, and foreign keys. The practicals include SQL commands to create tables, add/drop columns, insert/update/delete data, select data using conditions, perform calculations, combine data from multiple tables, and define relationships between tables.

Uploaded by

vishwajeet
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
4K views

DBMS Practical File

The document summarizes 10 practical SQL exercises covering key SQL topics like data definition, data manipulation, logical operators, comparison operators, functions, relational algebra, joins, subqueries, views, and foreign keys. The practicals include SQL commands to create tables, add/drop columns, insert/update/delete data, select data using conditions, perform calculations, combine data from multiple tables, and define relationships between tables.

Uploaded by

vishwajeet
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Practical No.

1
Problem Statement : Write the query for data definiton language

Command : CREATE

create table employee(emp_id number(3), name char(10), address varchar2(20),primary


key(roll_no));

Output :

Command : ALTER

alter table employee drop(roll_no)

Output :

Command : ALTER

alter table employee add(contact_no number(10));

Output :
Command : RENAME

rename employee to employee_info;

Output :
Practical No. 2
Problem Statement : Write the query for Data Manipulation Language

Command : INSERT

insert into employee values( '1' , 'alex' , 'delhi' );

Output :

Command : SELECT

select * from employee;

Output :

Command : SELECT

select name, address from employee;

Output :
Command : UPDATE

update employee_info set name='john' where name='dishu';

Output :

Command : DELETE

delete from employee_info where name='john';

Output :
Practical No. 3
Problem Statement : Write SQL queries using logical operators

Command : AND

select * from employee where emp_id='4' and name='peter' ;

Output :

Command : OR

select * from employee where emp_id='4' or name='alex' ;

Output :

Command : NOT

select * from employee where not emp_id = '3';

Output :
Command : BETWEEN

SELECT * FROM employee WHERE emp_id BETWEEN '2' AND '4';

Output :

Command : IN

SELECT * FROM employee_info WHERE name IN ('alex', 'peter', 'dishu');

Output :
Practical No. 4
Problem Statement : Write SQL queries using SQL operators

Command : EQUAL TO(=)

SELECT * FROM employee_info where emp_id='2';

Output :

Command : LESS THAN(<)

SELECT * FROM employee_info where emp_id<'3';


Output :

Command : GREATER THAN(>)

SELECT * FROM employee_info where emp_id>'2';

Output :
Command : LESS THAN EQUAL TO(<=)

SELECT * FROM employee_info where emp_id<='3';

Output :

Command : GREATER THAN EQUAL TO(>=)

SELECT * FROM employee_info where emp_id>='2';

Output :
Practical No. 5
Problem Statement : Write SQL queries using Character, Number, Date,
Group functions

Command : AVERAGE(AVG)

select AVG(order_price) as order_average from orders;

Output :

Command : COUNT

select count(customer) as customer_james from orders where customer='james';

Output :

Command : COUNT

select count(*) as no_of_orders from orders;

Output :
Command : COUNT

select count(distinct customer) as no_of_distinct_customer from orders

Output :

Command : MAX

select max(order_price) as max_order_price from orders;

Output :

Command : MIN

select min(order_price) as min_order_price from orders;

Output :
Practical No. 6
Problem Statement : Write SQL queries for Relational Algebra

Command : UNION

select name from employee union select name from student;

Output :

Command : UNION

select name from employee union all select name from student;

Output :
Command : INTERSECT

select name from employee intersect select name from student;

Output :

Command : MINUS

select name from employee minus select name from student;

Output :
Practical No. 7

Problem Statement : Write SQL queries for extracting data from more than
one table
Command : RIGHT JOIN

select orders1.order_id, customers.name, customers.customer_id, customers.payment


from orders1 RIGHT JOIN customers on orders1.customer_id= customers.customer_id;

Output :

Command : INNER JOIN

select orders1.order_id, customers.name, customers.customer_id, customers.payment


from orders1 INNER JOIN customers on orders1.customer_id= customers.customer_id;

Output :
Command : LEFT JOIN

select orders1.order_id, customers.name, customers.customer_id, customers.payment


from orders1 LEFT JOIN customers on orders1.customer_id= customers.customer_id;

Output :
Practical No. 8

Problem Statement : Write SQL statements for nested sub queries

Command :

select * from demo where marks >(select AVG(marks) from demo);

Output :

Command :

select MAX(salary) from employee2 where salary NOT IN(select MAX(salary) from
employee2);

Output :
Practical No. 9

Problem Statement : Perform the concept of views in the table

Command :

create view classess as(select name,roll_no from students where roll_no>'40')

Output :

Command :

select * from classes

Output :
Practical No. 10

Problem Statement : Perform the concept of referential integrity constraint


Command :

create table persons (name char(10),person_id number(20),age number(20),primary


key(person_id))

Output :

Command :

insert into persons values('pres','4','634');

Output :

Command

CREATE TABLE Orders (OrderID number(2), OrderNumber number(23),person_id number


(20),primary key(OrderID), FOREIGN KEY(person_id) REFERENCES persons(person_id));

Output :
Command

insert into Orders values('3','143313','6')

Output :

You might also like