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

Lab 5 SQL

1. The document provides instructions for completing a lab on declarative programming using SQL. It includes creating tables, inserting values, and writing queries to retrieve and manipulate data. 2. Students are asked to create tables for employees, students, recipes, movies, products, and jobs, and perform queries like finding max salaries, sorting data, and joining tables with foreign keys. 3. Additional advanced optional problems include more complex queries on a workers table like using aliases, uppercase conversions, finding unique values, and ordering results.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
872 views

Lab 5 SQL

1. The document provides instructions for completing a lab on declarative programming using SQL. It includes creating tables, inserting values, and writing queries to retrieve and manipulate data. 2. Students are asked to create tables for employees, students, recipes, movies, products, and jobs, and perform queries like finding max salaries, sorting data, and joining tables with foreign keys. 3. Additional advanced optional problems include more complex queries on a workers table like using aliases, uppercase conversions, finding unique values, and ordering results.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

LAB 5: Declarative Programming Paradigm

Practice(Optional):

1. Write a SQL lites statement to create a table names as employees including columns
employee_id, first_name, last_name, email, phone_numberhire_date, job_id, salary,
commission, manager_id and department_id
i) Insert values in the table and also execute the table structure
ii) Display the first name, last name of an employees whose salary is greater than
25,000

2. Create a table for Student with the following fields (Reg_no,stud_name,sex, and create a
table Dept with the following fields(dept_no primary key, dept_name)
a. Insert sample records and do the following
b. Display the student reg_no,name and dept_name
c. Display the student names ending with „ka‟
d. Display all the female students name
e. Display the student names by descending order
Graded:
1. Create the below table and execute the insert, update and the below select statements.

i) Write a query to display the total number of recipes available with the description
“Chinese”
ii) Write a query to display the id, name of the recipes with chef_id 'BL000002'.
iii) Write a query to display the description of the recipes whose name begins with 'P'.

2. Create a table movie of the below structure and assume data types.Movie_ID,
Movie_Name, Genre, Language, Rating ,Do the following queries
a. Update the movies rating by 10% and display it
b. Delete the movies with movie_id 102
c. Select movies whose rating is more than 3.
3. Create a course database with the following fields Product(ID, Prod_name,
Supplier_id,Unit_price,Package,OrderID),OrderItem(ID,Order_id,Product_id,Unit_price,
Quantity) using Foreign key
a. Display the total quantity of every product in the stock
b. Sort the Unit_price based on the supplier_id
c. Display the Product_name along with order_id and supplier_id
4. Write a SQL lite3 statement to create a table named as job including columns
job_id,job_title,Min-salary,Max_salary.job_id column does not contain any duplicate
value at the time of insertion

5. Write a SQL lite3 statement to create a table names as job_history including columns
employee_id, start_date, end_date, job_id and department_id and make sure that, the
employee_id column does not contain any duplicate value at the time of insertion and the
foreign key column job_id contain only those values which are exists in the jobs table.
Advanced: (Optional, More queries to practice)
1. Write a SQL lite 3 statement to create a table worker (WORKER_ID ,F_NAME ,
L_NAME ,SALARY ,JOINING_DATE ,DEPT)with appropriate data type and insert
values in the table . Do the following,
a. Write an SQL query to fetch “FIRST_NAME” from Worker table using the
alias name as <WORKER_NAME>
b. Write an SQL query to fetch “F_NAME” (First name) from Worker table in upper
case.
c. Write an SQL query to fetch unique values of DEPARTMENT from Worker table
d. Write an SQL query to print the first three characters of F_NAME (First
Name)from Worker table.
e. Write an SQL query to find the position of the alphabet („a‟) in the first name
column for ex :„Adam‟ from Worker table.
f. Write an SQL query that fetches the unique values of DEPT from Worker table
and prints its length.
g. Write an SQL query to print all Worker details from the Worker table order by
F_NAME Ascending
h. Write an SQL query to print details of workers excluding F_Name(First name) ,
for example “ram” and “Sam” from Worker table.
i. Write an SQL query to print details of the Workers whose F_NAME ends with „h‟
and contains 4 alphabets
j. Write an SQL query to print details of the Workers whose Salary lies between
100000 and 500000.
k. Write an SQL query to fetch the count of employees working in the department
„Administration‟.
l. Write an SQL query to fetch duplicate records having matching data in some fields
of a table.
m. Write an SQL query to show the second highest salary from a table
n. Write an SQL query to fetch the first 50% records from a table.
o. Write an SQL query to show the total average salary of all the employee

Create a table name product with product id, product name, price, manufacturer and quantity.
Insert rows into the tables.
a. Find the three most expensive products
b. Find the Products manufactured by a "ABC" company with a price less than 200
c. What products have a price between $20 and $200
d. How many products are in the database?
e. What product categories do we have?
f. What products with manufacturer names starting with A or C
g. Find the product with second largest price
h. Find the product whose price larger than average price
i. Find the top 5 priced products
j. Find the total quantity are product under each category

You might also like