Write one or more SQL statements to insert the following as a single transaction:
- Trip:
- Departure date: 14-JAN-2013
- Return date: 15-JAN-2013
- Vehicle id: 201
- Employee No: 48
- Manifest item:
- Pickup customer id:273
- Delivery customer id: 613
- Category: B
- Weight: 226
- Stop 1:
- Stop number: 1
- Reference: 273
- Stop date: 14-JAN-2013
- Stop 2:
- Stop number: 2
- Reference: 613
- Stop date: 15-JAN-2013
You may make the following assumptions:
- For the column TRIP.TRIP_ID there is a sequence called TRIP_SEQ and a trigger defined which together will automatically generate a new trip id value
- All items and stops will be part of the trip just defined
- Any error will trigger a rollback
- For the column MANIFEST.BARCODE there is a sequence and trigger which together will automatically generate a new barcode value
- A default category value of "A" is defined
- Other changes to the TRIP must be prevented during the transaction to ensure that the correct trip id value is used in the related records
- You may use the phrase TRIP_SEQ.NEXTVAL or TRIP_SEQ.CURRVAL
I have this but not sure if it is correct? I know there should be a ERD but it would not allow me to submitt it.
INSERT INTO trip (,departure_date, return_date, Vehicle_id,employee_no)
VALUES (TRIP_SEQ, 14-JAN-2013,15-JAN-2013,201,48);
INSERT INTO manifest (pickup_costomer_id, Delivery_customer_id,category,weight)
VALUES (TRIP_SEQNEXTVAL, 273,613,B,226);
INSERTINTO stop (stop_number, Reference, stop_date)
VALUES (TRIP_SEQNEXTVAL, 1, 273,14-JAN-2013)
INSERTINTO stop (stop_number, Reference, stop_date)
VALUES (TRIP_SEQNEXTVAL, 2, 613,15-JAN-2013)