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

DB-Library-System-Project

Uploaded by

mihraban833
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

DB-Library-System-Project

Uploaded by

mihraban833
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

University of Sulaimani

College of Commerce
Information Technology Department
2nd Stage – 1st Semester

Subject: Database System


Tables

Submitted By
Aram Rafiq
Rawezh Rostam
Linda Zana

Supervised by
Mr. Bilal Najmaddin Rashid

Submission Date: 2 Dec 2024

2024
Table of Contents
Table
s
1. Conceptual Design:.........................................................................2
1.1 Diagram:...........................................................................................................................2
2. The Books Table:............................................................................3
2.1 Inserting Values:...............................................................................................................3
2.2 Updating Values:...............................................................................................................3
2.3 Inserting a Null Value into Title Column:........................................................................4
3. Member Table:................................................................................4
3.1 ALTER Operations:..........................................................................................................4
3.2 Data Insertion:..................................................................................................................5
3.3 Data Manipulation:...........................................................................................................6
3.4 Violating Constraints:.......................................................................................................7
4. Borrowing Table:............................................................................8
4.1 ALTER Operation:............................................................................................................9
4.2 INSERT Operation:..........................................................................................................9
4.3 Data Manipulation:.........................................................................................................10
4.4 Violating Constraints:....................................................................................................11
5. Bonus:............................................................................................12
5.1 Librarians table:..............................................................................................................12
5.2 ALTER Operations:........................................................................................................12
5.3 TURNCATE Operate:.....................................................................................................12

1
1. Conceptual Design:
In this diagram we create a relation between the books and borrowing table and between
members and borrowing table:

1. Books and borrowing: Each book can be borrowed multiple times, and each borrowing
refers to one book. (One-to-Many).
2. Members and borrowing: each member can do several borrowings, and each borrowing
only refers to a specific member. (One-to-Many).

1.1 Diagram:

BorrowDate MemberID
BorrowID
BookID
FirstName
Price

Borrowing LastName
Title Books Members

Genre Gender

BookID
DateOfBirth
FK ReturnDate

Address
MemberID

FK

2
2. The Books Table:

2.1 Inserting Values:

2.2 Updating Values:

3
2.3 Inserting a Null Value into Title Column:

(Aram Rafiq)

3. Member Table:
Creating a members table:

Increasing Address Column with DEFAULT constraints, by default the members are from
Sulaimani city but if any member are not from there, the user can enter another city in the
Address field.

3.1 ALTER Operations:


1- Using ALTER table to add PhoneNumber Column and modify Address default field into
(Sulaimani):

4
2- Using ALTER table to rename the PhoneNumber Column to ContactNumber:

3- Using ALTER table to change the data type of the ContactNumber column to

VARCHAR(20):

4-
Using ALTER table to add a NOT NULL constraints to the ContactNumber column:

5- Using ALTER table to delete the ContactNumber column from members table:

The members table after the operations:

5
3.2 Data Insertion:

Insert the records:

We can see, the address by default is Sulaimani, if the user does not insert any other Address.

3.3 Data

Manipulation:
1- Updating
one of the
user’s email:

2- Delete a member’s records or data:

6
3- Select any members where their birth date is greater than (2005-1-1)

The result:

4- Select those members that address’s is (Halabja Shahid):

The result:

3.4 Violating Constraints:


1- Insert a member with duplicate email:

The error message:

7
2- Insert multiple choice of enum constraints:

The error message:

3. Insert null in the last name field:

4- The error message:

(Rawezh Rostam)

4. Borrowing Table:
Our third table is borrowing table which manages the borrowings of the books and when they
should be returned, this is how we code it:

This code gives us this structure:

8
Now I want to add another column for the table named “ExtendedDate” which is used for
extending the borrowing date for example if someone wanted to keep the book for a little
longer, they need to extend their return date.

4.1 ALTER Operation:


By using ALTER TABLE table_name ADD column_name; we can add a new column for
the table, like this:

By doing this we added a new column, and the structure will become like this:

Now we will insert data into the table.

4.2 INSERT Operation:


By using

INSERT INTO table_name(columns name)

VALUES(‘data’);

We can insert data into the table like this:

And this is its structure:

9
4.3 Data Manipulation:
Now let’s say we want to update a borrowing record’s ReturnDate we have to make sure it
checks the CHECK constraint.

And this is the result:

Now if a data deletes in the other tables, the related data in this table will get deleted too.

Here is the result:

As you can see one of the rows got deleted because one of the members who borrowed a
book got deleted from the table.

10
4.4 Violating Constraints:
If we want to insert a borrowing record where ReturnDate is earlier than the BorrowDate we
will get an error, because we gave it a check (CHECK(RturnDate>BorrowDate)).

It will give us this error:

(Linda Zana)

11
5. Bonus:
5.1 Librarians table:
Creating Librarians table:

5.2 ALTER Operations:


1- Adding LibrarianID column into borrowing table:

2- Add Foreign key for LibrarianID column in the borrowing table

Now we have 4 tables(Books – Members – Borrowing – Librarians):

5.3 TURNCATE Operate:


If we want to delete all the
data of the tables by using
TRUNCATE:

12
We cannot , and the error message:

Instead
of
using

TRUNCATE , we use DELETE operate to delete all the data of the tables:

13

You might also like