0% found this document useful (0 votes)
6 views4 pages

4 Solution

Uploaded by

test.root421
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

4 Solution

Uploaded by

test.root421
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment 4

Title: SQL Query Writing 2

Submitted By: Ponugumatla Bhavish

URN: 2023-B-04072004

Semester: III

Program: BCA

Course: Fundamentals of SQL and Data Modeling for the

Web
SQL queries for performing CRUD (Create, Read, Update, Delete) operations on the Library
Management System schema.

1. INSERT Statements (Create)

a. Insert a new member

sql

Copy code

INSERT INTO Member (Name, Email, PhoneNumber, MembershipStartDate)

VALUES ('John Doe', '[email protected]', '555-1234', '2024-11-23');

b. Insert a new book

sql

Copy code

INSERT INTO Book (Title, Author, Genre, PublishedYear, ISBN, AvailabilityStatus, PublisherID)

VALUES ('The Great Gatsby', 'F. Scott Fitzgerald', 'Fiction', 1925, '9780743273565', 'Available', 1);

c. Insert a new publisher

sql

Copy code

INSERT INTO Publisher (Name, Address, ContactInfo)

VALUES ('Penguin Random House', '1745 Broadway, New York, NY', '1-800-123-4567');

d. Insert a new borrowing transaction

sql

Copy code

INSERT INTO BorrowingTransaction (BorrowDate, DueDate, MemberID, BookID, StaffID)

VALUES ('2024-11-23', '2024-12-07', 1, 1, 1);

2. SELECT Statements (Read)

a. Retrieve all books

sql

Copy code

SELECT * FROM Book;

b. Retrieve a specific book by its ISBN

sql

Copy code
SELECT * FROM Book

WHERE ISBN = '9780743273565';

c. Retrieve all borrowing transactions for a specific member

sql

Copy code

SELECT * FROM BorrowingTransaction

WHERE MemberID = 1;

d. Retrieve all books that are currently available

sql

Copy code

SELECT * FROM Book

WHERE AvailabilityStatus = 'Available';

e. Retrieve all members who have borrowed a specific book

sql

Copy code

SELECT Member.Name, BorrowingTransaction.BorrowDate

FROM BorrowingTransaction

JOIN Member ON BorrowingTransaction.MemberID = Member.MemberID

WHERE BorrowingTransaction.BookID = 1;

3. UPDATE Statements (Update)

a. Update the availability status of a book

sql

Copy code

UPDATE Book

SET AvailabilityStatus = 'Checked Out'

WHERE BookID = 1;

b. Update the contact information of a member

sql

Copy code

UPDATE Member

SET PhoneNumber = '555-9876'


WHERE MemberID = 1;

c. Update the return date for a borrowing transaction (when a member returns a book)

sql

Copy code

UPDATE BorrowingTransaction

SET ReturnDate = '2024-11-25'

WHERE TransactionID = 1;

4. DELETE Statements (Delete)

a. Delete a book record (use caution)

sql

Copy code

DELETE FROM Book

WHERE BookID = 1;

b. Delete a member record (use caution)

sql

Copy code

DELETE FROM Member

WHERE MemberID = 1;

c. Delete a borrowing transaction record

sql

Copy code

DELETE FROM BorrowingTransaction

WHERE TransactionID = 1;

Notes:

● Always be cautious when performing DELETE operations to avoid accidentally removing


important records.

● The UPDATE queries will affect all records that match the WHERE clause, so ensure the
condition is specific.

● You can use JOINs in SELECT queries to retrieve data from multiple related tables.

● INSERT operations create new rows, and you should always ensure the data being inserted is
correct and consistent with your schema.

You might also like