Professional Documents
Culture Documents
Semester: 4th dd 4E
Section: Session:
Instructions:
Copying of the assignment will result in failure.
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.
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.
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.
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.
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:
Alter Table: Add a new column named "email" to the "Employees" table to store the email addresses of
employees.
Question 3:
Create Table: You are tasked with creating a table named "Students" with the following columns:
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:
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.
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.