0% found this document useful (0 votes)
14 views1 page

SQL Script for Inserting Orders

The document outlines a SQL script for processing a new order transaction. It includes steps to start a transaction, retrieve the latest order number, insert a new order for customer 145, add order line items, and commit the changes. The script ensures that all operations are executed within a single transaction for data integrity.

Uploaded by

Quý Bảo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

SQL Script for Inserting Orders

The document outlines a SQL script for processing a new order transaction. It includes steps to start a transaction, retrieve the latest order number, insert a new order for customer 145, add order line items, and commit the changes. The script ensures that all operations are executed within a single transaction for data integrity.

Uploaded by

Quý Bảo
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

- 1.

start a new transaction


START TRANSACTION;
-- 2. Get the latest order number
SELECT
@orderNumber:=MAX(orderNUmber)+1
FROM
orders;
-- 3. insert a new order for customer 145
INSERT INTO orders(orderNumber,
orderDate,
requiredDate,
shippedDate,
status,
customerNumber)
VALUES(@orderNumber,
'2005-05-31'
,
'2005-06-10'
,
'2005-06-11'
,
'In Process'
,
145);
8
Scriptthatperformstheabovesteps(ctn..) -- 4. Insert order line items
INSERT INTO orderdetails(orderNumber,
productCode,
quantityOrdered,
priceEach,
orderLineNumber)
VALUES(@orderNumber,
'S18_1749'
, 30,
'136'
, 1),
(@orderNumber,
'S18_2248'
, 50,
'55.09'
, 2);
-- 5. commit changes
COMMIT;

You might also like