DBMS LAB
DBMS LAB
-- LAB 1
-- Create schema
CREATE SCHEMA LAB_1;
-- Select schema
USE lAB_1;
-- 1. Add a new author named "Agatha Christie" with the biography "British
author known for her detective novels." to the Authors table in the Library
Management System database
INSERT INTO Authors (FirstName, LastName, Biography)
VALUES ('Agatha', 'Christie', 'British author known for her detective
novels.');
-- 6. Write a query to retrieve all members who joined after January 1, 2024.
SELECT * FROM Members
WHERE MembershipDate > '2024-01-01';
-- 7. Write a query to Add a CoverImage column to the Books table to store the
URL of the book cover image
ALTER TABLE Books
ADD COLUMN CoverImage VARCHAR(255);
-- 12. Write a query to Add a foreign key constraint to the Borrower table that
ensures the MemberID must refer to an existing MemberID in the Members table.
ALTER TABLE Borrower
ADD CONSTRAINT fk_member FOREIGN KEY (MemberID) REFERENCES Members(MemberID);
-- 13. Write a query to Find all books published between 1990 and 2000.
SELECT * FROM Books
WHERE PublicationYear BETWEEN 1990 AND 2000;
-- 14. Write a query to Find all authors whose last names start with the letter
"S".
SELECT * FROM Authors
WHERE LastName LIKE 'S%';
-- 15. Write a query to return the current date, time, and difference in days
between two date values.
SELECT CURDATE() AS CurrentDate, NOW() AS CurrentDateTime,
DATEDIFF('2024-12-01', '2024-01-01') AS DaysDifference;
-- LAB 1
-- Create schema
CREATE SCHEMA LAB_1;
-- Select schema
USE lAB_1;
-- 5. Write a query to get a list of all members and the books they have
borrowed.
SELECT
Members.FirstName AS MemberFirstName,
Members.LastName AS MemberLastName,
Books.Title AS BorrowedBookTitle
FROM
Members
LEFT JOIN
Borrower ON Members.MemberID = Borrower.MemberID
LEFT JOIN
Books ON Borrower.BookID = Books.BookID;
-- 7. List all books along with their author’s full name and publication year.
SELECT
Books.Title AS BookTitle,
CONCAT(Authors.FirstName, ' ', Authors.LastName) AS AuthorName,
Books.PublicationYear
FROM
Books
INNER JOIN
Authors ON Books.AuthorID = Authors.AuthorID;
-- LAB 3
-- Create schema
CREATE SCHEMA LAB_3;
-- Select schema
USE lAB_3;
DELIMITER ;
Krish Bhardwaj ( 2023sl70033 )
pg. 2
-- Step 3: Create a Trigger to Automatically Update Balance
DELIMITER $$
DELIMITER ;
OPEN TransactionCursor;
TransactionLoop: LOOP
FETCH TransactionCursor INTO TransactionID, AccountID, TransactionDate,
TransactionAmount, TransactionType;
IF Done THEN
LEAVE TransactionLoop;
END IF;
-- Display each transaction
SELECT TransactionID, AccountID, TransactionDate, TransactionAmount,
TransactionType;
END LOOP;
CLOSE TransactionCursor;
END$$
DELIMITER ;
Krish Bhardwaj ( 2023sl70033 )
pg. 3
-- Test the Stored Procedure
CALL TransferAmount(1, 2, 1000.00);