NPI000266 IDB Part 2
NPI000266 IDB Part 2
Table of Contents
Database Schema
1. SQL Code for Table Creation:
1. Database Selection:
MemberID INT PRIMARY KEY: Defines MemberID as an integer and the primary
key, uniquely identifying each member.
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
This image shows SQL code for creating the Books table in a database. The code performs
the following steps:
1. Table Structure:
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:
The following code creates the Copies table to store details of individual copies and
maintains referential integrity with the Books table.
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.
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.
Figure 5: Categories
The following picture is from the SQL code to create the Categories table in the database. It
will do the following:
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.
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:
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:
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
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
Execution Results:
Screenshot of Query Statements
Example Queries