0% found this document useful (0 votes)
12 views

NPI000266 IDB Part 2

afasdfaf

Uploaded by

newarsahil34
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)
12 views

NPI000266 IDB Part 2

afasdfaf

Uploaded by

newarsahil34
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/ 28

Acknowledgement

Table of Contents
Database Schema
1. SQL Code for Table Creation:

1.1 Members Table

Figure 1: Members Table


This image shows SQL code for creating the Members table in a database called college. The
code performs the following steps:

1. Database Selection:

 CREATE DATABASE college; creates a new database named "college."

 USE college; sets the context to the "college" database.

2. Members Table Structure:

 CREATE TABLE Members: Begins the creation of a table named Members.

 MemberID INT PRIMARY KEY: Defines MemberID as an integer and the primary
key, uniquely identifying each member.

 FirstName VARCHAR(50), LastName VARCHAR(50): Adds fields for FirstName


and LastName, each holding a maximum of 50 characters in length.

 ContactInfo VARCHAR(100): A field to store contact information, with a


maximum length of 100 characters.

 MembershipDate DATE: A field for the membership date, stored as a DATE type.
This code sets up a basic structure for storing member information in the Members
table.
1.2. Books Table

Figure 2: Books Table

This image shows SQL code for creating the Books table in a database. The code performs
the following steps:

1. Books Table Structure:


 CREATE TABLE Books: Begins the creation of a table named Books.
 BookID INT PRIMARY KEY: Defines BookID as an integer and the primary
key that will identify a single book uniquely.
 ISBN VARCHAR(13): Adds a field called ISBN to store the International
Standard Book Number of a book; the field can store up to 13 characters.
 Title VARCHAR(100): Adds a field called Title to store the name of the book
with a maximum limit of 100 characters.
 Author VARCHAR(50): This adds a field named Author, for storing the name of
the author. The maximum number of characters is set to 50 for this field.
 Genre VARCHAR(50): Adds a field called Genre to specify the type or genre of
the book, with a limit of 50 characters.
 TagColor VARCHAR(20): Adds a TagColor field to store a color tag associated
with the book, with a maximum length of 20 characters.
 PublisherID INT: Adds a field called PublisherID to store the ID of the publisher
of the book, most probably referring to another table called Publishers.
This code sets up the Books table to store the main details of each book, including title,
author, genre, and associated publisher, hence enabling the database to ensure that all
information concerning a book is well coordinated.

1.3. Copies Table

Figure 3: Copies Table


This image shows the SQL code to create a Copies table in the same database. The table is
designed to track individual copies of books, with each copy linked to a specific book
through a foreign key relationship.

1. Table Structure:

 CREATE TABLE Copies: Begins the creation of the Copies table.

 CopyID INT PRIMARY KEY: Defines the attribute CopyID as an integer and the
primary key; therefore, each copy is uniquely identified.

 BookID INT: A column to store ID of the book associated with, refer to Books
table.

 Status VARCHAR(20): The field to store the status of the copy, such as available
or borrowed; maximum length is 20 characters.
2. Foreign Key Constraint:

 FOREIGN KEY (BookID) REFERENCES Books(BookID): Creates a foreign key


relationship where every BookID in Copies corresponds to a valid BookID in the
table Books.

The following code creates the Copies table to store details of individual copies and
maintains referential integrity with the Books table.

1.4. Loans Table

Figure 4: Loans Table


This image shows SQL and instructions that are given to create a table called Loans in a
database. The code will do the following:

1. Loans Table Structure:

 CREATE TABLE Loans: Begins the process of creating a table named "Loans".
 LoanID INT PRIMARY KEY: It means that LoanID is an integer and a primary key,
which uniquely identifies each loan record.
 MemberID INT: Adds a field named MemberID to store the ID of the member who
borrowed an item, presumably referencing a table named Members.
 CopyID INT: Adds a field called CopyID to hold the ID of the copy of the item being
borrowed, presumably referencing a Copies table.
 BorrowDate DATE: Adds a field called BorrowDate to store the date when the item
was borrowed.
 ReturnDate DATE: Creates a new field called ReturnDate to hold the date that the
item is expected, or actually returned.
 FineAmount DECIMAL(10, 2): Adds a field named FineAmount to store any fine
amount in decimal with a maximum of 10 digits and 2 decimal places.

2. Foreign Key Constraints:

 FOREIGN KEY (MemberID) REFERENCES Members(MemberID): Establishes a


foreign key constraint on MemberID, linking it to the MemberID field in the
Members table.
 FOREIGN KEY (CopyID) REFERENCES Copies(CopyID): Sets a foreign key
constraint on CopyID, referencing the field by the same name in the Copies table.

This code sets up the Loans table for keeping records on borrowed items, linking each to a
member and identifying the specific copy of an item; it also keeps track of borrow and return
dates and any applicable fines.

1.5. Categories Table

Figure 5: Categories
The following picture is from the SQL code to create the Categories table in the database. It
will do the following:

1. Categories Table Structure:

 ALL CREATE TABLE Categories: Begins the process of creating a table named
Categories.
 CategoryID INT PRIMARY KEY – Defines CategoryID as an integer and the
primary key, which is used to uniquely identify each category.
 CategoryName VARCHAR(50): Adds a field called CategoryName to store the name
of a category with an upper limit of 50 characters.
 CategoryDescription VARCHAR(255): Adds a field called CategoryDescription to
store details or descriptions of the category, with the character maximum length set to
255.

This code sets up the Categories table to store basic information about different categories,
making sure that every entry is uniquely identifiable and descriptive.

1.6. Publishers Table

Figure 6: Publishers
The following is an image of SQL code that created the Publishers table in a database. The
steps this code takes are:

1. Publishers Table Structure:

 CREATE TABLE Publishers: Begins the creation of a table named Publishers.


 PublisherID INT PRIMARY KEY: This defines PublisherID as an integer and the
primary key; hence, it uniquely identifies each publisher.
 PublisherName VARCHAR(100): This adds a field named PublisherName to store
the name of the publisher with a maximum limit of 100 characters.
 Address VARCHAR(255): This adds a field called Address to store the address of the
publisher. The maximum length of this field is 255 characters.

This code sets up the Publishers table, which is meant to store basic information about
various publishers, making sure that every entry in a publisher is unique and descriptive.
1.7. Reservations Table

Figure 7: Reservations
The following picture shows an example SQL statement that is used to create a table called
Reservations in a database. Below is what happens in this SQL code:

1. Reservations Table Structure

 CREATE TABLE Reservations: This initiates the creation of a table named


Reservations.
 ReservationID INT PRIMARY KEY: This makes ReservationID an integer and the
primary key, hence unique for every reservation.
 MemberID INT: Adds a field called MemberID to store the ID of the member making
the booking.
 CopyID INT: Adds a field named CopyID to store the ID of the copy being reserved.
 ReservationDate DATE: Adds a field named ReservationDate to store the date when
the reservation was made.
 NotificationStatus VARCHAR(20): Adds a field named NotificationStatus to store
the status of any notifications associated with the reservation; limits the maximum to
20 characters.
 FOREIGN KEY (MemberID) REFERENCES Members(MemberID): This indicates
that the MemberID is a foreign key and references the field MemberID in the table
Members.
 FOREIGN KEY (CopyID) REFERENCES Copies(CopyID): This constraint specifies
that the column CopyID is a foreign key referring to the column CopyID in the table
Copies.

This code sets up the Reservations table, which stores reservation details and links the
reservations both to members and to the specific copies they reserve.

2. Execution Result:
Re-submit of Final Entity Relationship Diagram (ERD)

Figure 8: Final Crow Foot Notation ERD for the E-Library Management System

Documentation Note:

This ERD represents the final version for the E-Library Management System. It was
reviewed after the database schema was created whether it conformed to tables and
relationships that would have existed in the database. No modification was needed from the
original version. Thus, this confirmed that the entities, attributes, and relationships were set
correctly to meet the needs of the database design.
Database Diagram from the DBMS

Figure 9: Database Diagram Generated from MySQL Workbench


Data Definition Language (DDL)
Here’s each table with data types and constraints based on the ERD.

1. Members Table

2. Books Table
3. Copies Table

4. Loans Table

5. Categories Table
6. Publishers Table

7. Reservations Table

2. Execution Result:
Data Insertion
1. Insert into Publishers

2. Insert into Books

3. Insert into Categories

4. Insert into Members

5. Insert into Copies


6. Insert into Loans

7. Insert into Reservations

Execution Results:
Screenshot of Query Statements

Example Queries

1. Get all books along with their publisher information:

2. List of all members who have borrowed books:


3. Get all reservations along with member and copy details:

4. Find overdue loans (if any):


SQL-Data Manipulation Language (DML)
Here are the SQL DML queries to answer each of the required questions:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy