Databases
Normalisation questions
-
The publisher of several magazines has a relational database in which the details of each magazine are held. One of the tables in the database holds details of all the major articles in each magazine.
-
Write a description for entities
MagazineandArticle, showing for each table the primary key, a foreign key if applicable, and at least two other attributes, using the formatEntityName(primary_key,attribute1, attribute2, attribute3, ...,foreign_key)Magazine(magazine_id,name, issue_no, editor )Article(article_id,title, article_content, author,magazine_id)
-
Suggest, with a reason, an attribute in either table which it would be useful to define as a secondary key.
Magazine.nameas the name of a magazine is likely to be something that is looked up very frequently
-
-
A college department wishes to create a database to hold information about students and the courses they take. The relationship between students and courses is shown in the following entity relationship diagram.
Student | | attends | /|\ CourseEach course has a tutor who is in charge of the course.
Sample data held on the database is held below.
Student Number Student Name DateOfBirth Gender Course Number CourseName TeacherID Teacher Name 1111Bell, K 1998-01-14M COMP23Java1 8563Davey, A 2222Cope, F 1997-08-12F COMP23COMP16G101Java1
Intro to OOP
Animation856322991567Davey, A
Ross, M
Day, S3333Behr, K 1996-07-31M COMP16COMP34Intro to OOP
Database Design22993370Ross, M
Blaine, N-
Show how the data may be rearranged into relations which are in third normal form.
Student:
student_id surname initial date_of_birth gender 1111Bell K 1998-01-14M 2222Cope F 1997-08-12F 3333Behr K 1996-07-31M Teacher:
teacher_id surname initial 8563Davey A 2299Ross M 1567Day S 3370Blaine N Course:
course_id course_name teacher_id COMP23Java1 8563COMP16Intro to OOP 2299G101Animation 1567COMP34Database Design 3370StudentCourse:
course_id student_id 1111COMP232222COMP232222COMP162222G1013333COMP163333COMP34Rules for 1NF:
- [x] Each data item is atomic
- [x] Each row/record has a unique primary key
- [x] No records have repeating data
- [x] Each field should be unique
Rules for 2NF:
- [x] The table must be in 1NF
- [x] No partial dependencies
Rules for 3NF:
- [x] The table must be in 2NF
- [x] There are no non-key attributes that depend on another non-key attribute
- [x] Every non-key attribute is non-transitively dependent on the primary key
-
State two properties that the tables in a fully normalised database must have.
- No partial dependencies
- All attributes should depend transitively on the primary key
-
-
A museum has permanent displays but also runs a programme of special events. People may pay an annual fee to become Friends of the Museum. Friends can attend events, which they must book in advance. This, and other data about the museum, is stored in a relational database. Part of the entity-relationship (E-R) diagram is shown.
FRIEND | /|\ TICKET \|/ | EVENT-
- State the type of relationship between
FRIENDandTICKET.- One-to-many
- Explain the use of primary and foreign keys in
FRIENDandTICKETFRIENDwill have a primary key, which will uniquely identify each record- As one
FRIENDneeds to be able to have many tickets, its primary key needs to be a foreign key ofTICKET, and as oneEVENTneeds to issue many tickets, its primary key also needs to be a foreign key ofTICKET TICKETwill therefore contain 2 foreign keys that are used to link it to itsFRIENDandEVENTTICKETwill have a composite primary key, formed by theFRIENDtable's primary key and theEVENTtable's primary key (as oneTICKETis for only oneEVENTand only oneFRIEND)
- State the type of relationship between
-
When the database was being designed, an initial version of the diagram showed a direct relationship between
FRIENDandEVENT.Draw this initial E-R diagram with
FRIENDandEVENTonly.FRIEND \|/ | /|\ EVENT
Explain why
TICKETwas inserted.FRIEND-EVENTis a many-to-many relationship- In real database systems, many-to-many relationships cannot exist
- Therefore, a linker table is needed, to create one-to-many relationships with each other entity
-