DEV Community

Abdul Haseeb
Abdul Haseeb

Posted on

Sem V MYSQL Practical 6

1. Rename the column Pub of the Book table to Publisher.

ALTER TABLE Book RENAME COLUMN Pub TO Publisher;
Enter fullscreen mode Exit fullscreen mode

2. Delete the row from the Book_Issue table where the fine is zero.

DELETE FROM Book_Issue WHERE Fine = 0;
Enter fullscreen mode Exit fullscreen mode

3. Rename the Book_Issue table to Issue.

RENAME TABLE Book_Issue TO Issue;
Enter fullscreen mode Exit fullscreen mode

4. Display the information from the Book table for the ‘Thriller’ category.

SELECT * FROM Book WHERE Category = 'Thriller';
Enter fullscreen mode Exit fullscreen mode

5. Insert a row into the Book table.

INSERT INTO Book (BookID, Title, Author, Publisher, Category, Price, Qty) 
VALUES ('C142', 'Chacha Chaudhary', 'Pran Kumar', 'Diamond', 'Comics', 150, 200);
Enter fullscreen mode Exit fullscreen mode

6. Delete the column Fine from the Book_Issue table.

ALTER TABLE Issue DROP COLUMN Fine;
Enter fullscreen mode Exit fullscreen mode

7. Display the records of Comics type of books.

SELECT * FROM Book WHERE Category = 'Comics';
Enter fullscreen mode Exit fullscreen mode

8. Transaction Statements for Book Table (Cosmos):

i. Display original contents of the Book where the title of the book is ‘Cosmos’.
ii. Change the price of BookID S170 to 1050.
iii. Display the updated contents.
iv. Cancel the change with ROLLBACK.
v. Verify the original status.

-- Start the transaction
START TRANSACTION;

-- i. Display the original contents
SELECT * FROM Book WHERE Title = 'Cosmos';

-- ii. Update the price
UPDATE Book SET Price = 1050 WHERE BookID = 'S170';

-- iii. Display the updated contents
SELECT * FROM Book WHERE Title = 'Cosmos';

-- iv. Rollback the change
ROLLBACK;

-- v. Verify the original status
SELECT * FROM Book WHERE Title = 'Cosmos';
Enter fullscreen mode Exit fullscreen mode

9. Transaction Statements for Book Table (Let Us C):

i. Display original contents of the Book where the title of the book is ‘Let Us C’.
ii. Delete the row with BookID R185.
iii. Display the table contents.
iv. Save the changes with COMMIT.
v. Verify that ROLLBACK does not work after COMMIT.

-- Start the transaction
START TRANSACTION;

-- i. Display the original contents
SELECT * FROM Book WHERE Title = 'Let Us C';

-- ii. Delete the row with BookID 'R185'
DELETE FROM Book WHERE BookID = 'R185';

-- iii. Display the updated contents
SELECT * FROM Book;

-- iv. Save the changes
COMMIT;

-- v. Verify that rollback does not revert the changes
-- Trying rollback will not affect the data now
ROLLBACK;

-- Verify contents
SELECT * FROM Book;
Enter fullscreen mode Exit fullscreen mode

10. Delete the database LibraryXXX.

DROP DATABASE LibraryXXX;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)