75% found this document useful (4 votes)
19K views18 pages

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
75% found this document useful (4 votes)
19K views18 pages

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
  • Practical No. 1: Data Definition Language: Covers writing SQL queries related to Data Definition Language, including commands like CREATE and ALTER.
  • Practical No. 2: Data Manipulation Language: Focuses on writing SQL queries using Data Manipulation Language with commands such as INSERT, SELECT, UPDATE, and DELETE.
  • Practical No. 3: Logical Operators: Demonstrates writing SQL queries using logical operators including AND, OR, and NOT.
  • Practical No. 4: SQL Operators: Instruction on writing SQL queries using operators like EQUAL TO, LESS THAN, and GREATER THAN.
  • Practical No. 5: Character, Number, Date, Group Functions: Illustrates how to write SQL queries using various functions such as AVERAGE, COUNT, and MAX.
  • Practical No. 6: Relational Algebra: Explores writing SQL queries utilizing relational algebra operations like UNION, INTERSECT, and MINUS.
  • Practical No. 7: Data Extraction from Multiple Tables: Instructs on writing SQL queries for extracting data using JOIN operations from more than one table.
  • Practical No. 8: Nested Subqueries: Teaches SQL query writing involving nested subqueries for more complex data extraction.
  • Practical No. 9: Views: Covers concepts related to creating views in SQL for managing data presentation.
  • Practical No. 10: Referential Integrity Constraints: Discusses performing SQL operations that enforce referential integrity using primary and foreign keys.

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 :

Practical No. 1 
Problem Statement : Write the query for data definiton language 
Command : CREATE
create table employee(emp_
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 valu
Command : UPDATE
update employee_info set name='john' where name='dishu';
Output :
Command : DELETE
delete from employee_info
Practical No. 3
Problem Statement : Write SQL queries using logical operators
Command : AND
select * from employee where emp_
Command : BETWEEN
SELECT * FROM employee WHERE emp_id BETWEEN '2' AND '4';
Output :
Command : IN
SELECT * FROM employee_info
Practical No. 4
Problem Statement : Write SQL queries using SQL operators
Command : EQUAL TO(=)
SELECT * FROM employee_info w
Command :  LESS THAN EQUAL TO(<=)
SELECT * FROM employee_info where emp_id<='3';
Output :
Command :  GREATER THAN EQUAL TO(>=
Practical No. 5
Problem Statement : Write SQL queries using Character, Number, Date, 
Group functions
Command :  AVERAGE(AVG)
Command : COUNT
select count(distinct customer) as no_of_distinct_customer from orders
Output :
Command : MAX
select max(orde

You might also like