0% found this document useful (0 votes)
1 views3 pages

Assignment 1 SQL DDL Assignment MySQL Library Case Study

The document outlines the design and development of SQL DDL statements for a Library Management System using MySQL. It includes steps for creating a database, tables for students, books, and borrowing records, a view for borrowing details, and an index on book titles. Sample data insertion and optional file execution instructions are also provided.

Uploaded by

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

Assignment 1 SQL DDL Assignment MySQL Library Case Study

The document outlines the design and development of SQL DDL statements for a Library Management System using MySQL. It includes steps for creating a database, tables for students, books, and borrowing records, a view for borrowing details, and an index on book titles. Sample data insertion and optional file execution instructions are also provided.

Uploaded by

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

SQL DDL Assignment: MySQL Version - Library Management System

Title
Design and Develop SQL DDL statements in MySQL which demonstrate the use of SQL
objects such as Table, View, and Index.

Environment
- Operating System: Linux Fedora

- Tool: MySQL Terminal (mysql)

- SQL Objects Demonstrated: TABLE, VIEW, INDEX

Case Study: Library Management System


This system manages books, students, and book borrowing records using MySQL.

Step 1: Create and Use Database

CREATE DATABASE LibraryDB;


USE LibraryDB;

Step 2: Create Tables

-- Students Table
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Dept VARCHAR(30)
);

-- Books Table
CREATE TABLE Books (
BookID INT PRIMARY KEY,
Title VARCHAR(100),
Author VARCHAR(50),
CopiesAvailable INT
);

-- Borrow Table
CREATE TABLE Borrow (
BorrowID INT PRIMARY KEY,
StudentID INT,
BookID INT,
DateOfIssue DATE,
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (BookID) REFERENCES Books(BookID)
);

Step 3: Create a View

CREATE VIEW BorrowDetails AS


SELECT
b.BorrowID,
s.Name AS StudentName,
bk.Title AS BookTitle,
b.DateOfIssue
FROM
Borrow b
JOIN Students s ON b.StudentID = s.StudentID
JOIN Books bk ON b.BookID = bk.BookID;

To test view: SELECT * FROM BorrowDetails;

Step 4: Create an Index

CREATE INDEX idx_book_title ON Books(Title);

To check index: SHOW INDEX FROM Books;

Step 5: Insert Sample Data

INSERT INTO Students VALUES (1, 'Shraddha', 'AI&DS');


INSERT INTO Books VALUES (101, 'Database Systems', 'Navathe', 5);
INSERT INTO Borrow VALUES (1, 1, 101, CURDATE());
Step 6: Save and Run from File (Optional)

Save the code in a file named 'library_setup.sql' and run it using the
following command:

mysql -u root -p LibraryDB < library_setup.sql

Summary of SQL Objects Used

- TABLE: Students, Books, Borrow

- VIEW: BorrowDetails

- INDEX: idx_book_title

You might also like