Lab 7 - Foreign Key Constraints and Subqueries BOUCHINA OTHMANE
Lab 7 - Foreign Key Constraints and Subqueries BOUCHINA OTHMANE
LABORATORY MANUAL
BCS 306 - Database Management Systems
Spring 2024
Lab 7
Syntax: (ALTER)
ALTER TABLE child_table
ADD CONSTRAINT fk_name
FOREIGN KEY (child_column)
REFERENCES parent_table(parent_column)
ON UPDATE <action>
ON DELETE <action>;
Syntax: (subqueries)
3. Exercises for queries: (to able to answer this, you must download and
import this Database)
3.1. Using Invoices DB, Update the payment_total in the table invoices for the client with
id ‘5’ by multiplying the total invoice by 0.5.
EVIDENCE #1
TAKE A SCREENSHOT OF THE CALL TO THE SCRIPT AND THE OUTPUT OF
THE SCRIPT.
3.2. Using Invoices DB, Update the payment_total in the table invoices for the client
with name “Myworks” by multiplying the total invoice by 0.5.
EVIDENCE #2
TAKE A SCREENSHOT OF THE CALL TO THE SCRIPT AND THE OUTPUT OF
THE SCRIPT.
3.3. Using Invoices DB, Update the payment_total for clients whose city is in CA or NY
by multiplying the total_invoice by 0.5 and Payment_date by the current date.
EVIDENCE #3
TAKE A SCREENSHOT OF THE CALL TO THE SCRIPT AND THE OUTPUT OF
THE SCRIPT.
3.4. Using Invoices DB, Update the payment_date to be current date for the clients whose
payment_date is Null.
EVIDENCE #4
TAKE A SCREENSHOT OF THE CALL TO THE SCRIPT AND THE OUTPUT OF
THE SCRIPT.
3.5. Using sql_store DB, Update the comments to be “ Gold customer” for the clients
whose Points >3000.
EVIDENCE #5
TAKE A SCREENSHOT OF THE CALL TO THE SCRIPT AND THE OUTPUT OF
THE SCRIPT.
3.6. Using store DB, update the customer ID to 111 for a customer with the first_name
'Ines' in a store database, while ensuring referential integrity or foreign key
constraints.
EVIDENCE #6
TAKE A SCREENSHOT OF THE CALL TO THE SCRIPT AND THE OUTPUT OF
THE SCRIPT.
3.7. Using store DB, update the customer ID to 999 for a customer with the first name
'Levy' and add 1000 points to their account in a store database, while ensuring
referential integrity and foreign key constraints
EVIDENCE #7
TAKE A SCREENSHOT OF THE CALL TO THE SCRIPT AND THE OUTPUT OF
THE SCRIPT.
3.8. Use the ALTER TABLE statement to add a column named 'gender' with the data type
'varchar' after the 'last_name' column in the 'customers' table of a store database
EVIDENCE #8
TAKE A SCREENSHOT OF THE CALL TO THE SCRIPT AND THE OUTPUT OF THE
SCRIPT.
3.9. Use the ALTER TABLE statement to modify the 'orders' table, setting the foreign key
constraint to ON UPDATE CASCADE and ON DELETE CASCADE
EVIDENCE #9
TAKE A SCREENSHOT OF THE CALL TO THE SCRIPT AND THE OUTPUT OF
THE SCRIPT.
3.10. Use the ALTER TABLE statement to modify the 'order_items' table, setting the
foreign key constraint to ON UPDATE CASCADE and ON DELETE CASCADE.
EVIDENCE #10
TAKE A SCREENSHOT OF THE CALL TO THE SCRIPT AND THE OUTPUT OF
THE SCRIPT.
3.11. Using store DB, delete the customer with ID 7 while ensuring referential integrity and
foreign key constraints
EVIDENCE #11
TAKE A SCREENSHOT OF THE CALL TO THE SCRIPT AND THE OUTPUT OF
THE SCRIPT.
3.12. Using store DB, delete customers whose points are greater than 3000 while ensuring
referential integrity and foreign key constraints.
EVIDENCE #12
TAKE A SCREENSHOT OF THE CALL TO THE SCRIPT AND THE OUTPUT OF
THE SCRIPT.