0% found this document useful (0 votes)
25 views9 pages

DEC40073 Practical Work 1 Part2

Uploaded by

Sam Yew Jia Xian
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)
25 views9 pages

DEC40073 Practical Work 1 Part2

Uploaded by

Sam Yew Jia Xian
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/ 9

8-2-2024

Database system Practical 1

DTK4A
YEW JIA XIAN (SAM)
15DTK21F2011
Activity 1a

Figure 1: Entity Relational Diagram (ERD) for Book and Publisher


Activity 1b

Figure 2: ERD Relational Schema for Book and Publisher


Activity 1c

Figure 3: SQL coding


Table 1: Identifying SQL coding for each relational schema
Discussion Activity 2A

Activity 2b
Activity 2c
CREATE TABLE Staff
(
Staff_Name INT NOT NULL,
Position INT NOT NULL,
Salary INT NOT NULL,
Staff_Number INT NOT NULL,
PRIMARY KEY (Staff_Number)
);

CREATE TABLE Video


(
Member's_Number INT NOT NULL,
Video_Number INT NOT NULL,
Title INT NOT NULL,
Daily_Rental INT NOT NULL,
Date_oF_Return INT NOT NULL,
Date_Of_rent INT NOT NULL,
PRIMARY KEY (Video_Number)
);

CREATE TABLE Branch


(
Branch_Number INT NOT NULL,
City INT NOT NULL,
State INT NOT NULL,
Zip_Code INT NOT NULL,
Staff_Number INT NOT NULL,
PRIMARY KEY (Branch_Number),
FOREIGN KEY (Staff_Number) REFERENCES Staff(Staff_Number)
);

CREATE TABLE Manager_


(
Manager_Number INT NOT NULL,
Manager_Name INT NOT NULL,
Staff_Number INT NOT NULL,
Branch_Number INT NOT NULL,
PRIMARY KEY (Manager_Number),
FOREIGN KEY (Staff_Number) REFERENCES Staff(Staff_Number),
FOREIGN KEY (Branch_Number) REFERENCES Branch(Branch_Number)
);

CREATE TABLE Member


(
First_Name INT NOT NULL,
Last_Name INT NOT NULL,
Address INT NOT NULL,
Date INT NOT NULL,
Member_Number INT NOT NULL,
Number_of_videos_rent INT NOT NULL,
Video_Number INT NOT NULL,
PRIMARY KEY (Member_Number),
FOREIGN KEY (Video_Number) REFERENCES Video(Video_Number)
);

CREATE TABLE Register


(
Branch_Number INT NOT NULL,
Member_Number INT NOT NULL,
PRIMARY KEY (Branch_Number, Member_Number),
FOREIGN KEY (Branch_Number) REFERENCES Branch(Branch_Number),
FOREIGN KEY (Member_Number) REFERENCES Member(Member_Number)
);

Relational Schema Sql

CREATE TABLE Staff


(
Staff_Name INT NOT NULL,
Position INT NOT NULL,
Salary INT NOT NULL,
Staff_Number INT NOT NULL,
PRIMARY KEY (Staff_Number)
);

CREATE TABLE Video


(
Member's_Number INT NOT NULL,
Video_Number INT NOT NULL,
Title INT NOT NULL,
Daily_Rental INT NOT NULL,
Date_oF_Return INT NOT NULL,
Date_Of_rent INT NOT NULL,
PRIMARY KEY (Video_Number)
);

CREATE TABLE Branch


(
Branch_Number INT NOT NULL,
City INT NOT NULL,
State INT NOT NULL,
Zip_Code INT NOT NULL,
Staff_Number INT NOT NULL,
PRIMARY KEY (Branch_Number),
FOREIGN KEY (Staff_Number) REFERENCES
Staff(Staff_Number)
);

CREATE TABLE Manager_


(
Manager_Number INT NOT NULL,
Manager_Name INT NOT NULL,
Staff_Number INT NOT NULL,
Branch_Number INT NOT NULL,
PRIMARY KEY (Manager_Number),
FOREIGN KEY (Staff_Number) REFERENCES
Staff(Staff_Number),
FOREIGN KEY (Branch_Number) REFERENCES
Branch(Branch_Number)
);

CREATE TABLE Member


(
First_Name INT NOT NULL,
Last_Name INT NOT NULL,
Address INT NOT NULL,
Date INT NOT NULL,
Member_Number INT NOT NULL,
Number_of_videos_rent INT NOT NULL,
Video_Number INT NOT NULL,
PRIMARY KEY (Member_Number),
FOREIGN KEY (Video_Number) REFERENCES
Video(Video_Number)
);

CREATE TABLE Register


(
Branch_Number INT NOT NULL,
Member_Number INT NOT NULL,
PRIMARY KEY (Branch_Number, Member_Number),
FOREIGN KEY (Branch_Number) REFERENCES
Branch(Branch_Number),
FOREIGN KEY (Member_Number) REFERENCES
Member(Member_Number)
);

Conclusion

For the book and publisher there are two entities, while the one for department, project and
employees required three entities. Relationships are important to keep the ERD organized and
understandable for users to understand the layout. For each entity there should be at least an
attribute whether it is unique or composite, such as address, age and name. This application has
helped me to understand how programmers organize their systems. Each employee should be
assigned to a unique project in order for the company have a comfortable working schedule.

Each entity is labelled in a rectangle slot, each attribute is labelled in an oval slot, while reach
relationship I labelled in a diamond slot. Relationship between two entities can be many to one, one
to one, or many to many. The erd Can be a circular layout or a straight relational diagram.

You might also like