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

Lab Chapter # 5

1. The document provides instructions for a lab assignment involving performing SQL commands and queries using tables that were created in a script. 2. Students are instructed to add new rows to the ORDERS table, modify data in the ORDERS table, commit changes, and handle errors that may occur from invalid data entries or missing constraints. 3. Advanced tasks involve deleting and rolling back order records, and restructuring the CATEGORY data in the BOOKS table to use a lookup table with codes instead of plain text category names.

Uploaded by

Kovid Behl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
229 views

Lab Chapter # 5

1. The document provides instructions for a lab assignment involving performing SQL commands and queries using tables that were created in a script. 2. Students are instructed to add new rows to the ORDERS table, modify data in the ORDERS table, commit changes, and handle errors that may occur from invalid data entries or missing constraints. 3. Advanced tasks involve deleting and rolling back order records, and restructuring the CATEGORY data in the BOOKS table to use a lookup table with codes instead of plain text category names.

Uploaded by

Kovid Behl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Lab Chapter # 5

Total Marks: 10

Student Name : KOVID BEHL_________________ Student Id #: N01579154_______________

Lab exercises You need to be present in the class for your lab to be graded and are to be
submitted within 3 Hours after the class, failing to do the will result in ZERO grade.

Hands-On Assignments

To perform the following assignments, refer to the tables created in the


JLDB_Build_5.sql script attached with this assignment. Open the file and copy all
the contents and paste in SQL Developer. Select the commands and RUN to
execute the SQL commands.

1. Add a new row in the ORDERS table with the following data: Order# = 1021,
Customer# =1009, and Order date = July 20, 2009.
INSERT INTO ORDERS (Order#, Customer#, Orderdate)
VALUES (1021, 1009, '20-JUL-09');

2. Modify the zip code on order 1017 to 33222.


UPDATE ORDERS
SET ShipZip = '33222'
WHERE Order# = 1017;
3. Save the changes permanently to the database.
COMMIT;

4. Add a new row in the ORDERS table with the following data: Order# = 1022,
Customer# = 2000, and Order date = August 6, 2009. Describe the error
raised and what caused the error.
INSERT INTO ORDERS (Order#, Customer#, Orderdate)
VALUES (1022, 2000, '06-AUG-05');
Foreign key error due to customer 2000 not existing in customers table
5. Add a new row in the ORDERS table with the following data: Order# = 1023
and Customer# = 1009. Describe the error raised and what caused the
error.
INSERT INTO ORDERS (Order#, Customer#, Orderdate)
VALUES (1023, 1009);

Constraint error due to orderdate having a NOT NULL constraint


6. Create a script using substitution variables that allows a user to set a new
cost amount for a book based on the ISBN.
UPDATE BOOKS
SET cost = &cost
WHERE ISBN = '&ISBN';
7. Execute the script and set the following values: isbn = 1059831198 and cost
= $20.00.
UPDATE BOOKS
SET cost = &cost
WHERE ISBN = '&ISBN';

8. Execute a command that undoes the change in Step 7.


ROLLBACK;
9. Delete Order# 1005. You need to address both the master order record and
the related detail records.
DELETE FROM OrderItems WHERE Order# = 1005;
SAVEPOINT ONE;
DELETE FROM ORDERS WHERE Order# = 1005;

Execute a command that undoes the previous deletion.


10.
ROLLBACK;
ROLLBACK TO ONE;
Advanced Challenge
Currently, the contents of the Category column in the BOOKS table are the actual
name for each category. This structure presents a problem if one user enters
COMPUTER for the Computer category and another user enters COMPUTERS. To
avoid this and other problems that might occur, the database designers have
decided to create a CATEGORY table containing a code and description for each
category. The structure for the CATEGORY table should be as follows:

ALTER TABLE CATEGORY


MODIFY (CATCODE VARCHAR2(3),
CATDESC VARCHAR2(11));
INSERT INTO CATEGORY VALUES ('BUS', 'BUSINESS');
INSERT INTO CATEGORY VALUES ('CHN', 'CHILDREN');
INSERT INTO CATEGORY VALUES ('COK', 'COOKING');
INSERT INTO CATEGORY VALUES ('COM', 'COMPUTER');
INSERT INTO CATEGORY VALUES ('FAL', 'FAMILY LIFE');
INSERT INTO CATEGORY VALUES ('FIT', 'FITNESS');
INSERT INTO CATEGORY VALUES ('SEH', 'SELF HELP');
INSERT INTO CATEGORY VALUES ('LIT', 'LITERATURE');

You might also like