Question

In: Computer Science

Please Answer the questions listed in the comment section, 1 and 2! -- ==================================================================== -- SQL...

Please Answer the questions listed in the comment section, 1 and 2!

-- ====================================================================
-- SQL Script for Bookstore Database Records
--    This script demonstrates the use of transactions for Unit 13 Exercise
--
--      Created by: Jennifer Rosato
--      Created on: 12/2013
--      Modified by: David Vosen
--      Modified on: 11/2016
--      Modified on: 11/2018 Add DBCC LOG(CIS_3107_##, 1) to view 
--      transactions.
-- ==================================================================== 

--SELECT * FROM customer;
--SELECT * FROM invoice;
--SELECT * FROM line;
--SELECT * FROM product;
-- cus_code for the invoice order: 1000006
-- inv_number for the new invoice: 4000006
-- p_code for the product ordered: 3000007


-- example that rolls back the transaction
BEGIN TRANSACTION;                      -- the DBMS starts keeping a transaction log here

        -- verify that the new records in invoice and line are NOT there
        SELECT * FROM invoice WHERE cus_code = '1000006';
        SELECT * FROM line WHERE inv_number = '4000006';
        SELECT * FROM product WHERE p_code = '3000007';
        
        -- add an invoice using the current date
        INSERT INTO invoice
        VALUES ('4000006', '1000006', GETDATE());

        -- add a line item to the invoice
        INSERT INTO line
        VALUES ('5000011', '4000006', '3000007', 1, 29.99);

        -- update the product table to remove the amount of the product 
        -- that was sold
        UPDATE product
        SET p_qoh = p_qoh - 1
        WHERE p_code = 3000007;
        
        -- verify that the new records in invoice and line are there
        SELECT * FROM invoice WHERE cus_code = '1000006';
        SELECT * FROM line WHERE inv_number = '4000006';
        SELECT * FROM product WHERE p_code = '3000007';

ROLLBACK;

-- verify that the new records in invoice and line are no longer there and that 
-- the original amount of the product on hand is the same
SELECT * FROM invoice WHERE cus_code = '1000006';
SELECT * FROM line WHERE inv_number = '4000006';
SELECT * FROM product WHERE p_code = '3000007';

-- example that commits the transaction
BEGIN TRANSACTION;                      -- the DBMS starts keeping a transaction log here
        
        -- add an invoice using the current date
        INSERT INTO invoice
        VALUES (4000006, 1000006, GETDATE());

        -- add a line item to the invoice
        INSERT INTO line
        VALUES (5000011, 4000006, 3000007, 1, 29.99);

        -- update the product table to remove the amount of the product 
        -- that was sold
        UPDATE product
        SET p_qoh = p_qoh - 1
        WHERE p_code = 3000007;
        
        -- verify that the new records in invoice and line are there
        SELECT * FROM invoice WHERE cus_code = '1000006';
        SELECT * FROM line WHERE inv_number = '4000006';
        SELECT * FROM product WHERE p_code = '3000007';

COMMIT; 


-- DBCC LOG(CIS_3107_00, 1)

/*
DBCC LOG(yourdatabasename, typeofoutput) where typeofoutput:
0: Return only the minimum of information for each operation -- the operation, its context and the transaction ID. (Default)
1: As 0, but also retrieve any flags and the log record length.
2: As 1, but also retrieve the object name, index name, page ID and slot ID.
3: Full informational dump of each operation.
4: As 3 but includes a hex dump of the current transaction log row.
*/



-- 1. create YOUR OWN example that rolls back the transaction 
BEGIN TRANSACTION;                      -- the DBMS starts keeping a transaction log here

        -- verify that your new records in invoice and line are NOT there 
        SELECT * FROM  WHERE 
        SELECT * FROM  WHERE 
        SELECT * FROM  WHERE    
        
        -- add an invoice using the current date
        INSERT INTO  
        VALUES 

        -- add a different line item to the invoice
        INSERT INTO  
        VALUES 

        -- update the product table to remove the amount of the product 
        -- that was sold for that line item
        UPDATE  
        SET 
        WHERE 
        
        -- verify that your new records in invoice and line are there 
        SELECT * FROM  WHERE 
        SELECT * FROM  WHERE 
        SELECT * FROM  WHERE 

ROLLBACK;
 
-- 2. Now use your example to commit your transaction now that you have tested it
BEGIN TRANSACTION;                      -- the DBMS starts keeping a transaction log here
        
        -- add the invoice using the current date 

        -- add your line item to the invoice
 

        -- update the product table to remove the amount of the product 
        -- that was sold
 
    -- verify that the changes have been made to the tables

COMMIT; 

Solutions

Expert Solution

SELECT * FROM invoice WHERE cus_code = '4000010'; 
SELECT * FROM line WHERE inv_number = '1004030'; 
SELECT * FROM product WHERE p_code = '677919'; 

BEGIN TRANSACTION; 

INSERT INTO invoice VALUES ('1004030', '4000010', '03-08-2019'); 
INSERT INTO line VALUES ('129391', '1004030', '677919', 1, 29.99); 

UPDATE product SET p_qoh = p_qoh - 1 WHERE p_code = 677919; 
SELECT * FROM invoice WHERE cus_code = '4000010'; 
SELECT * FROM line WHERE inv_number = '1004030'; 
SELECT * FROM product WHERE p_code = '677919'; 
ROLLBACK;


SELECT * FROM invoice WHERE cus_code = '4000010';
SELECT * FROM line WHERE inv_number = '1004030';
SELECT * FROM product WHERE p_code = '677919';

BEGIN TRANSACTION;                     
        
        INSERT INTO invoice VALUES ('1004030', '4000010', '03-08-2019');

        INSERT INTO line VALUES ('129391', '1004030', '677919', 1, 29.99);

        UPDATE product
        SET p_qoh = p_qoh - 1
        WHERE p_code = 677919;
        
        -- verify that the new records in invoice and line are there
        SELECT * FROM invoice WHERE cus_code = '4000010';
        SELECT * FROM line WHERE inv_number = '1004030';
        SELECT * FROM product WHERE p_code = '677919';

COMMIT; 

Related Solutions

This is t a relational database please write SQL queries to solve the listed questions. The...
This is t a relational database please write SQL queries to solve the listed questions. The database is a variation of the “Movie Database” . There are several differences in it, so look it over carefully before writing your SQL queries Notes: TheaterNum, MovieNum, and ActorNum are numeric primary key fields in their respective tables. Movie and actor names are not assumed to be unique unless specified otherwise in a question. In the THEATER table, Capacity is the number of...
There are 10 questions listed to ask your Financial Advisor. Please list them and comment on...
There are 10 questions listed to ask your Financial Advisor. Please list them and comment on why you think each is important. 1. What experience do you have? 2. What are your qualifications? 3. What financial planning services do you offer? 4. What is your approach to financial planning? 5. What types of clients do you typically work with? 6. Will you be the only financial planner working with me? 7. How will I pay for your financial planning services?...
Please discuss and answer the two questions listed below in detail. 1. What are the different...
Please discuss and answer the two questions listed below in detail. 1. What are the different types of pension plans? How are they different and how do they impact the employer and the employee? What type of plan do most companies have? 2. Discuss the amortization of Accumulated OCI (Gain/Loss). How do you amortize the accumulated Gain/Loss (illustrate with examples)?
This section consists of THREE (3) questions. Answer ANY TWO (2) questions. 1. “Management of retail...
This section consists of THREE (3) questions. Answer ANY TWO (2) questions. 1. “Management of retail organizations carefully design the approaches about their investments into three key areas: customer loyalty programs, customer data, and technologies aimed at making the shopping experience easier, safer and more efficient”. Analyze the above statement by providing explanation on the appropriate strategies that should utilize by online retailers in order to be successful into the key areas as stated above. 2. “Consumers have greater expectations...
Please answer the following questions: 1- Summarize the Household Survey Data section of the news release...
Please answer the following questions: 1- Summarize the Household Survey Data section of the news release (page #1-#2). 2- Summarize the Establishment Survey Data section of the new release (page #2-#3). 3- Is the downward trend in unemployment due to higher employment or higher amount of discouraged workers? 4- How do you think the new unemployment numbers may affect the national inflation rate? Use the following link as the source: https://www.bls.gov/news.release/pdf/empsit.pdf
Please answer the following questions: 1- Summarize the Household Survey Data section of the news release...
Please answer the following questions: 1- Summarize the Household Survey Data section of the news release (page #1-#2). 2- Summarize the Establishment Survey Data section of the new release (page #2-#3). 3- Is the downward trend in unemployment due to higher employment or higher amount of discouraged workers? 4- How do you think the new unemployment numbers may affect the national inflation rate? Use the following link as the source: DATA AVAILABLE IN THE FOLLOWING LINK https://www.bls.gov/news.release/pdf/empsit.pdf
Chapter 12 in the “Questions and Exercises” section of 12.4 answer questions #1 & 3. In...
Chapter 12 in the “Questions and Exercises” section of 12.4 answer questions #1 & 3. In what ways is data collected at Rent the Runway? How does data enhance the customer experience? How does data enhance firm operations? How does it help cut costs and improve efficiency?
1. Can you please describe the different kinds of joins used in SQL? 2. What SQL...
1. Can you please describe the different kinds of joins used in SQL? 2. What SQL syntax would you use to ensure you are not returning duplicates in your data sets? 3. What SQL syntax would you use to change data in a table if you had write access to the table? Having write access means the data manipulation would occur in the table being pulled from. 4. What SQL syntax would you use to change data in a table...
Please answer questions in the order listed. You do not need to be completely correct, but...
Please answer questions in the order listed. You do not need to be completely correct, but I do need to see an honest effort. For this post, YOU MUST SHOW YOUR WORK, on any question requiring math. This is to make it so that I can see where exactly where you mis-stepped in your calculation or logic, and/or so that your classmates can learn from you. 5.) MicroServe needs $100,000 to upgrade its warehouse. Dayna, the CEO of MicroServe, thinks...
Please answer the following questions on the 2008 financial crisis please answer 1-2 paragraphs each. What...
Please answer the following questions on the 2008 financial crisis please answer 1-2 paragraphs each. What was the financial situation that consumed Wall Street and the Federal government in 2008? Which government officials played critical roles in addressing the financial crisis, and how did they address it? How would you critique the ethical culture of Wall Street and those insiders on Wall Street who triggered the financial crisis?    4. Who is to blame? Are there any good guys here?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT