Lab 13 (SOLUTION)
Lab 13 (SOLUTION)
Lab 13 (SOLUTION)
Task:
A. Create a Stored Procedure to Add a New Book to the Library
1. Create a table for books
create database books;
-- Step 1: Create a table for books
CREATE TABLE books (
book_id INT PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL,
publication_year INT,shelfno int
);
-- Inserting sample data into the books table
INSERT INTO books (title, author, publication_year,shelfno) VALUES
('The Catcher in the Rye', 'J.D. Salinger', 1951,45),
('To Kill a Mockingbird', 'Harper Lee', 1960,67),
('1984', 'George Orwell', 1949,89),
('Pride and Prejudice', 'Jane Austen', 1813,12),
('The Hobbit', 'J.R.R. Tolkien', 1937,32);
2. Create a stored procedure to add a new book
DELIMITER //
DELIMITER ;
3. Call the stored procedure to add a new book
B. Create, alter, read and delete Stored procedure of a table from your project
a. CREATE/READ PROCEDURE;
DELIMITER //
DELIMITER ;
CALL GetUserAccounts()
ALTER PROCEDURE:
DROP PROCEDURE IF EXISTS AddUserAccount;
DELIMITER //
DELIMITER ;
CALL GetUserAccounts()
DROP PROCEDURE:
Deliverables:
Complete your lab tasks in SQL workbench and submit a word file with queries and the
screenshots of the results to all the questions attempted. Upload it on LMS. Late submissions
will not be accepted.