54
DATABASE DESIGN I IST 210: Organization of Data IST210 1

DATABASE DESIGN I IST 210: Organization of Data IST210 1

Embed Size (px)

Citation preview

Page 1: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 1

DATABASE DESIGN IIST 210: Organization of Data

Page 2: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 2

I want a database to maintain departments in my company. Store information about my employees, their projects and assignments. I

want ….

$$$

User requirement

A database

YOUR JOB!

Data Modeling (Ch.4)

Database Design (Ch.5)

Page 3: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 3

Two-Step Approach: Step 1

• Input: User requirement; Output: E-R Diagram• Use Entity-Relationship Diagram (E-R Diagram) to

capture all user requirements

Data Modeling (Ch.4)

Database Design (Ch.5)

Page 4: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 4

Two-Step Approach: Step 2

Data Modeling (Ch.4)

Database Design (Ch.5)

• Input: E-R diagram; Output: A database• Transferring a data model to a relational database

• Entities Relations• Relationships Foreign keys and extra

Page 5: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 5

Chapter Key Objective

Data Model (E-R Diagram) Relational Model (Tables)

1. Entity Table• Entity name Table name• Identifier Primary key• Attributes Attributes

2. Relationship Foreign key or a new table• Determined by the maximal cardinality

3. Specify the attribute properties• Data type• Key• Required

• Determined by the minimal cardinality• Remarks

Page 6: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 6

E-R Diagram Tables

1. Entity Table• Entity name Table name• Identifier Primary key• Attributes Attributes

2. Relationship Foreign key or a new table3. Specify the attribute properties

Page 7: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 7

Example

LockerID

LockerRoomLockerSize

EmployeeID

NameOfficeNumberOfficePhone

LOCKEREMPLOYEE1) Entity name Table name2) Identifier Primary key3) Attributes Attributes

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone)LOCKER(LockerID, LockerRoom, LockerSize)

*primary key: use underline

Page 8: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 8

E-R Diagram Tables

1. Entity Table• Entity name Table name• Identifier Primary key• Attributes Attributes

2. Relationship Foreign key or a new table• Determined by the maximal cardinality

3. Specify the attribute properties

Page 9: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 9

Maximal Cardinality

• 1:1 (one-to-one) Relationship

• 1:N (one-to-many) Relationship

• N:M (many-to-many) RelationshipEntity A Entity B

Entity A Entity B

Entity A Entity B

Page 10: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 10

1:1 Relationship

LockerID

LockerRoom

LockerSize

1 #2 10

5 #2 5

EMPLOYEE LOCKER

Relationship is not captured yet!

Add foreign key ?

Employee ID

Name OfficeNumber

OfficePhone

4 Tom 281 9182

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone)LOCKER(LockerID, LockerRoom, LockerSize)

Page 11: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 11

Employee ID

Name OfficeNumber

OfficePhone

LockerID

4 Tom 281 9182 1

LockerID

LockerRoom

LockerSize

1 #2 10

5 #2 5

EMPLOYEE LOCKER

Employee 4 owns locker 1; locker 1 belongs to employee 4.

Employee ID

Name OfficeNumber

OfficePhone

4 Tom 281 9182

LockerID

LockerRoom

LockerSize

EmployeeID

1 #2 10 4

5 #2 5

EMPLOYEE LOCKER

LockerID

LockerRoom

LockerSize

EmployeeID

1 #2 10 4

5 #2 5

EMPLOYEE LOCKER

Employee ID

Name OfficeNumber

OfficePhone

LockerID

4 Tom 281 9182 1

Option A

Option B

Option C

Page 12: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 12

1:1 Relationship

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone, LockerID)LOCKER(LockerID, LockerRoom, LockerSize)

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone)LOCKER(LockerID, LockerRoom, LockerSize, EmployeeID)

Option A

Option B

Both options are correct. Option A is preferred.• If choosing Option A, since every employee has one locker, LockerID must

have a value in EMPLOYEE table.• If choosing Option B, since some lockers does not belong to anyone,

EmployeeID will be NULL value for some lockers and it takes extra space. (See the previous slide, Option B needs one more cell.)

*foreign key: italic

Page 13: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 13

1:1 Relationship• The maximum cardinality determines how a relationship is

represented• 1:1 relationship

• The key from one relation is placed in the other as a foreign key• It does not matter which table receives the foreign key• We prefer the option taking less space

Page 14: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 14

1:N Relationship

Employee ID

LastName

FirstName

OfficeNumber

OfficePhone

4 Green Tom 281 9182

LockerID

LockerRoom

LockerSize

1 #2 10

5 #2 5

EMPLOYEE LOCKER

Relationship is not captured yet! Add foreign key ?

LockerID

LockerRoomLockerSize

EmployeeID

NameOfficeNumberOfficePhone

LOCKEREMPLOYEE

Assume one-to-many relationship

Page 15: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 15

Employee ID

Name OfficeNumber

OfficePhone

LockerID

4 Tom 281 9182 1, 5

LockerID

LockerRoom

LockerSize

1 #2 10

5 #2 5

EMPLOYEE LOCKER

Employee 4 owns locker 1 and 5.

Employee ID

Name OfficeNumber

OfficePhone

4 Tom 281 9182

LockerID

LockerRoom

LockerSize

EmployeeID

1 #2 10 4

5 #2 5 4

EMPLOYEE LOCKER

EMPLOYEE LOCKER

EmployeeID

Name OfficeNumber

OfficePhone

LockerID

4 Tom 281 9182 1, 5

Option A

Option B

Option C

LockerID

LockerRoom

LockerSize

EmployeeID

1 #2 10 4

5 #2 5 4

Page 16: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 16

1:N Relationship

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone)LOCKER(LockerID, LockerRoom, LockerSize, EmployeeID)

Page 17: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 17

1:N Relationship• Like a 1:1 relationship, a 1:N relationship is saved by

placing the key from one table into another as a foreign key

• However, in a 1:N the foreign key always goes into the many-side of the relationship• The 1 side is called the parent• The N side is called the child

Page 18: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 18

N:M Relationship

Employee ID

Name OfficeNumber

OfficePhone

4 Tom 281 9182

10 John 777 1829

LockerID

LockerRoom

LockerSize

1 #2 10

5 #2 5

EMPLOYEE LOCKER

Relationship is not captured yet! Add foreign key ?

LockerID

LockerRoomLockerSize

EmployeeID

NameOfficeNumberOfficePhone

LOCKEREMPLOYEE

Assume many-to-many relationship

Page 19: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 19

Employee ID

Name OfficeNumber

OfficePhone

LockerID

4 Tom 281 9182 1, 5

10 John 777 1829 1

LockerNumber

LockerRoom

LockerSize

1 #2 10

5 #2 5

EMPLOYEE LOCKER

Employee 4 owns locker 1 and 5. Employee 10 owns locker 1.

Employee ID

Name OfficeNumber

OfficePhone

4 Tom 281 9182

10 John 777 1829

LockerID

LockerRoom

LockerSize

EmployeeID

1 #2 10 4, 10

5 #2 5 4

EMPLOYEE LOCKER

Option A

Option B

Page 20: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 20

Employee ID

Name OfficeNumber

OfficePhone

4 Tom 281 9182

10 John 777 1829

LockerID

LockerRoom

LockerSize

1 #2 10

5 #2 5

EMPLOYEE LOCKER

EmployeeID

LockerID

4 1

4 5

10 1

ASSIGNMENT

NOT SIMPLY ADDING FOREIGN KEYS! CREATE ANOTHER TABLE!

Employee 4 owns locker 1 and 5. Employee 10 owns locker 1.

Page 21: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 21

N:M Relationship

EMPLOYEE(EmployeeID, LastName, FirstName, OfficeNumber, OfficePhone)LOCKER(LockerID, LockerRoom, LockerSize)ASSIGNMENT(EmployeeID, LockerID)

Note: EmployeeID and LockerID are both primary keys and foreign keys in ASSIGNMENT table

Page 22: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 22

N:M Relationship• To represent a N:M relationship in relational design, a new

table must be created. • This table is called an intersection table

• An intersection table has a composite key consisting of the keys from each of the tables that it connects

Page 23: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 23

Relationship Summary

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone, LockerID)LOCKER(LockerID, LockerRoom, LockerSize)

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone)LOCKER(LockerID, LockerRoom, LockerSize, EmployeeID)

N:M add an intersection table

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone)LOCKER(LockerID, LockerRoom, LockerSize)ASSIGNMENT(EmployeeID, LockerID)

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone)LOCKER(LockerID, LockerRoom, LockerSize, EmployeeID)

1:N add a foreign key to the many-side table

1:1 add a foreign key to either table

or

Page 24: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 24

In-class Exercise 1Transform this diagram into tables

UserID

NameEmail

SpotID

LocationMonthlyCost

USERPARKING

Page 25: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 25

In-class Exercise 1Transform this diagram into tables

UserID

NameEmail

SpotID

LocationMonthlyCost

USERPARKING

PARKING(SpotID, Location, MonthlyCost)USER(UserID, Name, Email, SpotID)

Page 26: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 26

In-class Exercise 1: Notes

PARKING(SpotID, Location, MonthlyCost)USER(UserID, Name, Email, SpotID)

PARKING(SpotID, Location, MonthlyCost, UserID)USER(UserID, Name, Email)

Note: both options are correct, but the first one is preferred because of the minimal cardinality of SpotID is mandatory.

Page 27: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 27

In-class Exercise 2

BuildingNameApartmentID

NumberOfBedNumberOfBathRent

BuildingName

Address

APARTMENTBUILDING

Transform this diagram into tables

Page 28: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 28

In-class Exercise 2Transform this diagram into tables

BUILDING(BuildingName, Address)APARTMENT(BuildingName, ApartmentID, NumberOfBedrooms, NumberofBaths, Rent)

Page 29: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 29

In-class Exercise 2: Notes

BUILDING(BuildingName, Address)APARTMENT(BuildingName, ApartmentID, NumberOfBedrooms, NumberofBaths, Rent)

Notes:* A common mistake is making ApartmentID as the only primary key. (BuildingName, ApartmentID) should a composite key for APARTMENT * Another common mistake is to create a duplicate attribute BuildingName in APARTMENT. Or forget to make BuildingName as the foreign key

Page 30: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 30

In-class Exercise 3

CourseID

CourseNameInstructor

StudentID

StudentNameEmail

COURSESTUDENT

Transform this diagram into tables

Page 31: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 31

In-class Exercise 3

CourseID

CourseNameInstructor

StudentID

StudentNameEmail

COURSESTUDENT

Transform this diagram into tables

STUDENT(StudentID, StudentName, Email)COURSE(CourseID, CourseName, Instructor)REGISTRATION(StudentID, CourseID)

Page 32: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 32

In-class Exercise 3: Notes

STUDENT(StudentID, StudentName, Email)COURSE(CourseID, CourseName, Instructor)REGISTRATION(StudentID, CourseID)

Notes:* In REGISTRATION table, StudetID and CourseID are both primary key and foreign key. So you should give both underline and italic (wave underline in hand-written format) to them.

Page 33: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 33

E-R Diagram Tables

1. Entity Table• Entity name Table name• Identifier Primary key• Attributes Attributes

2. Relationship Foreign key or a new table• Determined by the maximal cardinality• 1:1 add a foreign key to either table• 1:N add a foreign key to the many-side table• N:M add an intersection table

3. Specify the attribute properties

Page 34: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 34

E-R Diagram Tables

1. Entity Table• Entity name Table name• Identifier Primary key• Attributes Attributes

2. Relationship Foreign key or a new table• Determined by the maximal cardinality

3. Specify the attribute properties• Data type• Key• Required

• Determined by the minimal cardinality• Remarks

Page 35: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 35

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone, LockerID)LOCKER(LockerID, LockerRoom, LockerSize)

EMPLOYEE table

Column Name Data Type Key Required Remarks

LockerID

LockerRoom

LockerSize

LOCKER table

Column Name Data Type Key Required Remarks

EmployeeID

Name

OfficeNumber

OfficePhone

LockerID

Page 36: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 36

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone, LockerID)LOCKER(LockerID, LockerRoom, LockerSize)

EMPLOYEE table

Column Name Data Type

LockerID int

LockerRoom char(10)

LockerSize float

LOCKER table

Column Name Data Type

EmployeeID int

Name char(50)

OfficeNumber char(20)

OfficePhone char(12)

LockerID int

Data Type• Determine the data types based on the type

of these attributes• Data types must be the types defined in

SQL• http://technet.microsoft.com/en-us/library/

ms187752.aspx

• Data type of a foreign key must be the same type as its referred primary key

• LockerID in EMPLOYEE table must have the same data type as LockerID in LOCKER because LockerID is a foreign key in EMPLOYEE

Page 37: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 37

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone, LockerID)LOCKER(LockerID, LockerRoom, LockerSize)

EMPLOYEE table

Column Name Data Type

LockerID Primary key

LockerRoom

LockerSize

LOCKER table

Column Name Key

EmployeeID Primary key

Name

OfficeNumber

OfficePhone

LockerID Foreign key

Key• Specify primary key and foreign key(s) in the

table

Page 38: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 38

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone, LockerID)LOCKER(LockerID, LockerRoom, LockerSize)

EMPLOYEE table

Column Name Required

LockerID Yes

LockerRoom Yes

LockerSize Yes

LOCKER table

Column Name Required

EmployeeID Yes

Name Yes

OfficeNumber No

OfficePhone No

LockerID Yes

Required• Whether an attribute is required or not

determines whether we allow NULL value for this attribute

• Primary key must be required• Normal attributes are determined based on

requirements or common sense• “not required” is preferred

• Foreign key is determined by minimum cardinality

• An employee must have at least one locker. So LockerID is required in EMPLOYEE

Page 39: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 39

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone, LockerID)LOCKER(LockerID, LockerRoom, LockerSize)

EMPLOYEE table

Column Name

Remarks

LockerID Surrogate key: initial value = 1 Increment = 1

LockerRoom

LockerSize Default value: 10

LOCKER table

Column Name

Remarks

EmployeeID Surrogate key: initial value = 1 Increment = 1

Name

OfficeNumber

OfficePhone Format: ###-###-####

LockerID Reference: LOCKER

Remarks• If a primary key is a surrogate key,

specify the initial value and increment

• If an attribute is a foreign key, specify which table it refers to

• If an attribute has a required format, specify the format

• If an attribute has a default value, specify the value

Page 40: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 40

EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone, LockerID)LOCKER(LockerID, LockerRoom, LockerSize)

EMPLOYEE table

Column Name

Data Type

Key Required

Remarks

LockerID int Primary key

Yes Surrogate key: initial value = 1 Increment = 1

LockerRoom char(10) Yes

LockerSize float Yes Default value: 10

LOCKER table

Column Name

Data Type

Key Required Remarks

EmployeeID int Primary key

Yes Surrogate key: initial value = 1 Increment = 1

Name char(50) Yes

OfficeNumber char(20) No

OfficePhone char(12) No Format: ###-###-####

LockerID int Foreign key

Yes Reference: LOCKER

Now we complete converting an E-R diagram to tablesNext, we can use SQL to create a real database

Page 41: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 41

In-class Exercise 1

PARKING(SpotID, Location, MonthlyCost)USER(UserID, Name, Email, SpotID)

Page 42: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 42

PARKING(SpotID, Location, MonthlyCost)USER(UserID, Name, Email, SpotID)PARKING table

Column Name

Data Type

Key Required Remarks

UserID

Name

Email

SpotID

USER table

Column Name

Data Type

Key Required Remarks

SpotID

Location

MonthlyCost

In-class Exercise 1

Page 43: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 43

PARKING table

Column Name

Data Type

Key Required Remarks

UserID int Primary key

Yes Surrogate key: initial value = 1 Increment = 1

Name char(100) Yes

Email char(50) No

SpotID int Foreign key

Yes Reference: PARKING

USER table

Column Name

Data Type

Key Required Remarks

SpotID int Primary key

Yes Surrogate key: initial value = 1 Increment = 1

Location char(50) Yes

MonthlyCost int Yes Default: 50

PARKING(SpotID, Location, MonthlyCost)USER(UserID, Name, Email, SpotID)

Page 44: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 44

PARKING table

Column Name

Data Type

Key Required

Remarks

UserID int Primary key

Yes Surrogate key: initial value = 1 Increment = 1

Name char(100) Yes

Email char(50) No

SpotID int Foreign key

Yes Reference: PARKING

USER table

Column Name

Data Type

Key Required

Remarks

SpotID int Primary key

Yes Surrogate key: initial value = 1 Increment = 1

Location char(50) Yes

MonthlyCost int Yes Default: 50

Notes: • See the red parts• Char is not a data type, char(50) is a data type. If you use char, you need

to specify the max length• When you can use other data types, do not use char. For example, it is

better to use int for MonthlyCost instead of using char

PARKING(SpotID, Location, MonthlyCost)USER(UserID, Name, Email, SpotID)

Page 45: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 45

In-class Exercise 2Transform this diagram into tables

BUILDING(BuildingName, Address)APARTMENT(BuildingName, ApartmentID, NumberOfBedrooms, NumberofBaths, Rent)

Page 46: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 46

BUILDING table

Column Name

Data Type

Key Required Remarks

BuildingName

ApartmentID

NumberOfBed

NumberOfBath

Rent

APARTMENT table

Column Name

Data Type

Key Required Remarks

BuildingName

Address

BUILDING(BuildingName, Address)APARTMENT(BuildingName, ApartmentID, NumberOfBedrooms, NumberofBaths, Rent)

In-class Exercise 2

Page 47: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 47

BUILDING table

Column Name

Data Type

Key Required Remarks

BuildingName Char(20) Primary key, foreign key

Yes Reference: BUILDING

ApartmentID int Primary key Yes

NumberOfBed float Yes

NumberOfBath float Yes

Rent float Yes

APARTMENT table

Column Name

Data Type

Key Required Remarks

BuildingName

Char(20) Primary key

Yes

Address Char(100) Yes Format: street, city, state, zip code

BUILDING(BuildingName, Address)APARTMENT(BuildingName, ApartmentID, NumberOfBedrooms, NumberofBaths, Rent)

Page 48: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 48

BUILDING table

Column Name

Data Type

Key Required Remarks

BuildingName Char(20) Primary key, foreign key

Yes Reference: BUILDING

ApartmentID int Primary key Yes

NumberOfBed float Yes

NumberOfBath

float Yes

Rent float Yes

APARTMENT table

Column Name

Data Type

Key Required Remarks

BuildingName

Char(20) Primary key

Yes

Address Char(100) Yes Format: street, city, state, zip code

Notes: • ApartmentID should NOT be a surrogate key. In real scenarios, we are using

some meaningful ApartmentIDs, such as 100 or 201 instead of a meaningless system-generated id.

• Use float for #ofBed, #ofBath, and Rent. Because #ofBath could be 1.5 and rent could be $890.50, which are not integers.

Page 49: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 49

In-class Exercise 3Transform this diagram into tables

STUDENT(StudentID, StudentName, Email)COURSE(CourseID, CourseName, Instructor)REGISTRATION(StudentID, CourseID)

Page 50: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 50

STUDENT(StudentID, StudentName, Email)COURSE(CourseID, CourseName, Instructor)REGISTRATION(StudentID, CourseID)

STUDENT table

Column Name

Data Type Key Required Remarks

CourseID

CourseName

Instructor

COURSE table

Column Name

Data Type

Key Required Remarks

StudentID

StudentName

Email

Column Name

Data Type

Key Required Remarks

StudentID

CourseID

REGISTRATION table

In-class Exercise 3

Page 51: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 51

STUDENT(StudentID, StudentName, Email)COURSE(CourseID, CourseName, Instructor)REGISTRATION(StudentID, CourseID)

STUDENT table

Column Name

Data Type Key Required Remarks

CourseID Char(20) Primary key

Yes Format: DepartmentName + CourseNumber

CourseName Char(50) Yes

Instructor Char(100) No

COURSE table

Column Name

Data Type Key Required Remarks

StudentID int Primary key

Yes Surrogate key: initial value = 1 Increment = 1

StudentName Char(100) Yes

Email Char(50) No

Column Name

Data Type

Key Required Remarks

StudentID int Primary key, foreign key Yes Reference: STUDENT

CourseID Char(20) Primary key, foreign key Yes Reference: COURSE

REGISTRATION table

Page 52: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 52

STUDENT table

Column Name

Data Type Key Required Remarks

CourseID Char(20) Primary key

Yes Format: DepartmentName + CourseNumber

CourseName Char(50) Yes

Instructor Char(100) No

COURSE table

Column Name

Data Type

Key Required Remarks

StudentID int Primary key

Yes Surrogate key: initial value = 1 Increment = 1

StudentName Char(100) Yes

Email Char(50) No

Column Name

Data Type

Key Required Remarks

StudentID int Primary key, foreign key

Yes Reference: STUDENT

CourseID Char(20) Primary key, foreign key

Yes Reference: COURSE

REGISTRATION table

Notes:• A CourseID should not be integer, for example, “IST210” is a courseID.

CourseName for IST210 is “Organization of the data”.

Page 53: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 53

E-R Diagram Tables

1. Entity Table• Entity name Table name• Identifier Primary key• Attributes Attributes

2. Relationship Foreign key or a new table3. Specify the attribute properties

Page 54: DATABASE DESIGN I IST 210: Organization of Data IST210 1

IST210 54

Attendance check?