Project Scenario: Library Management System
Objective
The goal of this project is to create a Library Management System database that will store
information about books, authors, and members. This will involve creating the database,
defining tables, and populating them with sample data.
Step 1: Create the Database
1. Database Name: LibraryDB
○ This database will contain all tables and data related to the library.
Step 2: Define the Tables
We will create three tables:
● Authors: To store information about authors.
● Books: To store information about books in the library.
● Members: To store information about library members.
Table Structure
1. Authors Table
○ AuthorID (INT, Primary Key, Auto-increment)
○ FirstName (NVARCHAR(50), NOT NULL)
○ LastName (NVARCHAR(50), NOT NULL)
○ BirthDate (DATE)
2. Books Table
○ BookID (INT, Primary Key, Auto-increment)
○ Title (NVARCHAR(100), NOT NULL)
○ AuthorID (INT, Foreign Key referencing Authors)
○ PublicationYear (YEAR)
○ Genre (NVARCHAR(50))
3. Members Table
○ MemberID (INT, Primary Key, Auto-increment)
○ FullName (NVARCHAR(100), NOT NULL)
○ MembershipDate (DATE)
○ Email (NVARCHAR(100))
Step 3: SQL Commands
Now, let’s create the database and tables, and insert sample data.
Create the Database
CREATE DATABASE LibraryDB;
GO
USE LibraryDB;
GO
Create the Authors Table
CREATE TABLE Authors (
AuthorID INT PRIMARY KEY IDENTITY(1,1),
FirstName NVARCHAR(50) NOT NULL,
LastName NVARCHAR(50) NOT NULL,
BirthDate DATE
);
GO
Create the Books Table
CREATE TABLE Books (
BookID INT PRIMARY KEY IDENTITY(1,1),
Title NVARCHAR(100) NOT NULL,
AuthorID INT,
PublicationYear YEAR,
Genre NVARCHAR(50),
FOREIGN KEY (AuthorID) REFERENCES Authors(AuthorID)
);
GO
Create the Members Table
CREATE TABLE Members (
MemberID INT PRIMARY KEY IDENTITY(1,1),
FullName NVARCHAR(100) NOT NULL,
MembershipDate DATE,
Email NVARCHAR(100)
);
GO
Step 4: Insert Sample Data
Now we will populate the tables with sample data.
Insert Authors
INSERT INTO Authors (FirstName, LastName, BirthDate)
VALUES
('George', 'Orwell', '1903-06-25'),
('Jane', 'Austen', '1775-12-16'),
('Mark', 'Twain', '1835-11-30');
GO
Insert Books
INSERT INTO Books (Title, AuthorID, PublicationYear, Genre)
VALUES
('1984', 1, 1949, 'Dystopian'),
('Pride and Prejudice', 2, 1813, 'Romance'),
('The Adventures of Huckleberry Finn', 3, 1884, 'Adventure');
GO
Insert Members
INSERT INTO Members (FullName, MembershipDate, Email)
VALUES
('Alice Johnson', '2023-01-15', '
[email protected]'),
('Bob Smith', '2023-02-20', '
[email protected]'),
('Charlie Brown', '2023-03-05', '
[email protected]');
GO
Step 5: Querying the Data
To verify that the data has been added correctly, you can run the following queries:
Retrieve Authors
SELECT * FROM Authors;
GO
Retrieve Books
SELECT * FROM Books;
GO
Retrieve Members
SELECT * FROM Members;
GO
Summary
In this project, we successfully created a LibraryDB database, defined tables for authors,
books, and members, and inserted sample data. This foundational setup can be expanded with
additional features such as:
● Transactions: Handling book loans.
● Search Functionality: Finding books or members.
● Reporting: Generating reports on book availability and member activity.