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

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
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 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?
Section 1 Short Answer Questions: 2. What is the relationship between logistics and Marketing? 3. What...
Section 1 Short Answer Questions: 2. What is the relationship between logistics and Marketing? 3. What is the relationship between logistics and Production? 4. What is the difference between logistics network design and logistics process design? Provide an example
Section 1. The following questions are conceptual questions based on chapters 1 and 2 (weeks 1...
Section 1. The following questions are conceptual questions based on chapters 1 and 2 (weeks 1 and 2 of the lecture notes). • Suppose that a survey is being planned for purposes of estimating the average number of hours exercising daily by adults (18 years of age or older) living in a certain community. A list of all individuals living in the community is not available; however, a list of all households is available at the office of community clerk....
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment...
Question 1: Group by and Aggregates: Write SQL statements to answer the following questions using Assignment 4’s schema (Customer-Invoice-Line-Product-Vendor). Make sure that your SQL script runs without any errors. Submit your answers in a .SQL file. 1 (2 Points) - Find the count of distinctvendors thatsupplied products that are priced lowerthan 185? 2 (2 Points) - For each vendor, find their product that has the lowest product quantity. Your output should include vendor code, vendor name, product description and product...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT