You are on page 1of 3

THE SUPERIOR UNIVERSITY LAHORE

Semester: 4th dd 4E
Section: Session:

Faculty of Computer Science and Information Technology Deadline:


Subject: Database(LAB) Total Marks: 10

Instructions:
 Copying of the assignment will result in failure.

 Assignment should be submitted in word or pdf.

Question # Sub-Question CLO # Domain and BT Level Total Marks


1 1 Cognitive 04
2 3 Cognitive 03
3 3 Cognitive 03

Question 1:

Imagine you are managing a database for a small online retail store. Your task involves creating and
maintaining tables to manage product inventory and customer orders.

Table Creation using DDL:

Create a table named Products to store product information. Include columns for product_id,
product_name, price, and quantity_available. Ensure that the product_id column is unique and not null.
Set a default value of 0 for quantity_available.

Create a table named Orders to track customer orders. Include columns for order_id, customer_name,
product_id, quantity_ordered, and order_date. Use appropriate constraints to enforce referential
integrity between the Orders.product_id and Products.product_id columns.

Table Population using DML:

Insert at least 5 records into the Products table with sample product information including product
names, prices, and quantities available.

Add records into the Orders table to simulate customer orders. Ensure that each order references a valid
product from the Products table. Include information such as customer names, product IDs, quantities
ordered, and order dates.

Data Modification using DML:

Update the price of a product with a specific product_id in the Products table to reflect a price change.

Change the quantity available for a product in the Products table based on recent sales from the Orders
table.
Constraint Alteration using DDL:

Alter the Products table to add a new column named discount_percentage. Ensure that this column
accepts values only within the range of 0 to 100.

Data Deletion using DML:

Delete a product record from the Products table with a specific product_id. Ensure that any related
records in the Orders table are appropriately handled.

Question 2:

Create Table: Create a table named "Employees" with columns: employee_id, first_name, last_name,
gender, date_of_birth, department_id, and salary. Ensure that employee_id serves as the primary key
and cannot be NULL. first_name and last_name should also not accept NULL values. The gender column
should only accept 'M' for male and 'F' for female.

Insert Records: Insert the following records into the "Employees" table:

Update Record: Update the salary of employee with ID 1 to 60000.00.

Delete Record: Delete the employee with ID 3 from the table.

Alter Table: Add a new column named "email" to the "Employees" table to store the email addresses of
employees.

Truncate Table: Remove all records from the "Employees" table.

Drop Table: Drop the "Employees" table from the database.

Question 3:

Create Table: You are tasked with creating a table named "Students" with the following columns:

student_id (primary key)

first_name (not null)

last_name (not null)

age (default 18, must be between 18 and 25)

grade (must be between 0 and 100) Ensure that appropriate constraints are applied.

Insert Records: Insert three records into the "Students" table with the following details:

Student 1: John Smith, age 20, grade 85

Student 2: Emily Johnson, age 22, grade 92

Student 3: Alex Brown, age 19, grade 78


Update Record: Update the grade of student "John Smith" to 90.

Delete Record: Delete the record of student "Alex Brown" from the table.

Alter Table: Add a new column named "address" to the "Students" table to store the student's address.

Truncate Table: Remove all records from the "Students" table.

Drop Table: Drop the "Students" table from the database.

Create Index: Create an index on the last_name column of the "Students" table to improve search
performance.

Unique Constraint: Alter the "Students" table to enforce that no two students can have the same
combination of first name and last name.

Foreign Key Constraint: Create a new table named "Courses" with columns course_id (primary key) and
course_name. Then, alter the "Students" table to include a foreign key constraint referencing the
course_id column of the "Courses" table.

You might also like