0% found this document useful (0 votes)
36 views

LAB-QuestionsBBAF For Lab Sheet

The document outlines 7 labs covering SQL topics like data definition and manipulation language, aggregation functions, constraints, views, and joins. Lab 1 demonstrates creating and modifying database objects like tables and deleting records. Lab 2 focuses on inserting, updating, and deleting data. Lab 3 covers where clauses and subqueries. Lab 4 introduces aggregation functions. Lab 5 deals with constraints. Lab 6 is about views. Lab 7 examines different types of joins between tables. Each lab includes example queries to practice the relevant SQL concepts.

Uploaded by

Nabin Joshi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

LAB-QuestionsBBAF For Lab Sheet

The document outlines 7 labs covering SQL topics like data definition and manipulation language, aggregation functions, constraints, views, and joins. Lab 1 demonstrates creating and modifying database objects like tables and deleting records. Lab 2 focuses on inserting, updating, and deleting data. Lab 3 covers where clauses and subqueries. Lab 4 introduces aggregation functions. Lab 5 deals with constraints. Lab 6 is about views. Lab 7 examines different types of joins between tables. Each lab includes example queries to practice the relevant SQL concepts.

Uploaded by

Nabin Joshi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

LAB 1.

Using DDL
Q.N.1. Create, show and use database as a database NCC.
Q.N.2. Create Table Student with primary key.
Q.N.3. Describe table student.
Q.N.4. Rename table employee with new name emp.
Q.N.5.Listing all tables.
Q.N.6. Delete table employee from database NCC.
Q.N.7. Write a query to delete all employee record who are from Bhaktapur.

Query:
DELETE FROM employee
WHERE emp_address=”Bhaktapur”;

LAB 2.
Using DML
Q.N.1. Insert id, name, address, phone no in table employee.
Q.N.2. Write a SQL statement to make table empty.
Q.N.3. Update table student set new address kathmandu whose id is 2.
Q.N.4. Delete student's name from table student whose id is 101.
Q.N.5. Display all records of students from student table.
Q.N.7. Write a query to create table department where fid is working as a foreign key.
Q.N.8. Write a query which will increase the salary of each department by Rs 1000
Query:
UPDATE employee
SET salary=salary+1000;

Q.N.9. Write a query to increase salary of employees by 5% whose salary is more than 9000.
Query:
UPDATE employee
SET salary=salary+0.5*salary
WHERE salary>9000;
Q.N.10. Write a query to change the department id of employees whose old department id is 201.
The new department id should be 501.
Query:
UPDATE employee
SET dep_id=501
WHERE dep_id=201;

LAB 3
Using where clause/Sub-Query

Q.N.1. Write a query to retrieve all records of employee having salary greater than 50000.

Q.N. 2. Write a query to select name, address and salary of all employees who are from
Kathmandu.

Q.N. 3. Write a query to select name, address and salary of all employees whose department id is
2002

Q.N.4. Write a query to list all records of employees who are from KTM and whose salary is less
than 20000.
- SELECT * FROM employee
WHERE address='KTM' AND salary<20000;

Q.N.5. Write a query to retrieve names of employee who are from Kathmandu or whose
department id is 2001.

Query:
SELECT * FROM employee
WHERE address='KTM' OR dep_id=10;
Q.N.6. Write a SQL query to list names of employee from employee table where the names starts
with ”M” and ends with “n”.
Query:
SELECT emp_name
FROM employee
WHERE emp_name LIKE “M%n”;
Q.7. Write a SQL query to list id and names of employee from employee table where the names starts
with ”M” end with “n” and has exactly 5 characters.
Query:
SELECT emp_id, emp_name
FROM employee
WHERE emp_name LIKE “M _ _ _ n”;

LAB- 4
Using aggregate function:
1. Write a query to find the maximum salary of employee.
2. Write a query to find the average salary of employee.
3. Write a query to find the total number of records in department table.
4. Write a query to find the number of employees from Kathmandu.
5. Write a query to find the total salary of employee table.

LAB-5

Using Constraints

Q1. Create table student where all fiends should be not null.
Q2. Create table exam marks and sname should be unique.
Q3. Create table college where cid should be PRIMARY KEY.
Q4. Create table customer and Orders and orders table should have foreign key.
Q5. Create table atm where atmid should be greater than 0.
Q6. Create table bank where default balance should be 1000.

LAB-6
Using View
Q.1. Create following views and display them:

view_2002 from dep_id from employee table.


Query:
CREATE VIEW view_2002 AS
SELECT * FROM employee WHERE dep_id=2002;

Q.2. Create view vwit with department name is IT.


Q.3. Create view vwemp with e_name,address from employee table.

LAB-7

Using Joins

Q.1. Write a query to retrieve employee name and department name using natural join.

Q.2. Write a query to retrieve all information from employee and department table using natural
join.

Q.3. Write a query to retrieve customer name and order price using left outer join.

Q.4. Write a query to retrieve all the information from customer and order table using left outer
join.

Q.5. Write a query to retrieve fname, dname using right outer join.

Q.N.6. Write a query to retrieve all the information from faculty and department table using right
outer join.

Q.N.6. Print or display employee's name who are working in IT department.

You might also like