Databases Flashcards
What is an entity in entity-relationship modelling?
An entity is a category of object, person, event or thing of interest about which data is to be recorded.
Examples: Employee, Film, Actor, Product, Recipe, Ingredient
Each entity in a database system has attributes.
What entities might there be for a database used to store data about dentist appointments at a particular dentist surgery?
E.g. Dentist, Patient, Appointment.
What attributes might the entity “Dentist” have in a database used to store data about dentist appointments at a particular dentist surgery?
E.g. DentistID, Title, FirstName, Surname, Qualification
What attributes might the entity “Patient” have in a database used to store data about dentist appointments at a particular dentist surgery?
E.g. PatientID, Title, FirstName, Surname, EmailAddress, TelephoneNumber
What attributes might the entity “Appointment” have in a database used to store data about dentist appointments at a particular dentist surgery?
E.g. StartTime, EndTime, PatientID, DentistID, Cost, Procedure
How are entity descriptions normally written?
An entity description is typically written using the format
Entity1 (Attribute1, Attribute2)
E.g.
Dentist(Title, Firstname, Surname, Qualification)
Patient(Title, Firstname, Surname, Address, Telephone)
Write an entity description for the entity Pet with the attributes Name, Species, Age, and Owner.
Pet(Name, Species, Age, Owner)
Write an entity description for the entity Student with the attributes FirstName, Surname, Age, YearGroup, and EmailAddress.
Student(FirstName, Surname, Age, YearGroup, EmailAddress)
What is an entity identifier?
Each entity needs to have an entity identifier which uniquely identifies the entity.
In a relational database, the entity identifier is known as the primary key.
An ID number can be used as a primary key for Dentist and Patient:
Dentist(DentistID, Title, Firstname, Surname, Qualification)
What are the three types of relationships that can exist between entities?
One-to-one
One-to-many
Many-to-many
Give an example of a one-to-one relationship.
Husband and Wife (in the UK)
Country and Prime Minister
Give an example of a one-to-many relationship.
Customer and order (a customer can have multiple orders)
Borrower and library book (a borrower can borrow multiple books)
School and pupil (a school can have multiple pupils)
Give an example of a many-to-many relationship.
Student and course
Student and teacher
Stock item and supplier
Film and actor
What is an entity-relationship diagram?
A diagrammatic way of representing the relationships between the entities in a database.
To show the relationship between two entities, both the degree and the name of the relationship need to be specified.
How do relational databases work?
In a relational database, a separate table is created for each entity identified in the system.
Where a relationship exists between two entities, an extra field called a foreign key links the tables.
What’s a foreign key?
A foreign key is an attribute that creates a joint between two tables. It is the attribute that is common to both tables.
The primary key in one table is the foreign key in the table to which it is linked.
How do you link tables that have a many-to-many relationship with each other?
When there is a many-to-many relationship between two entities, tables cannot be directly linked.
E.g. the relationship between Student and Course. A student takes many courses, and the same course is taken by many students.
In this case, an extra table is needed to link the two entities.
For this example, this table could be called Enrolment.
What is a composite primary key?
Sometimes 2 or even more attributes are needed to uniquely define a record.
For example, in a customer order consisting of many different order lines, each order line may be uniquely identified by the two attributes orderNumber and orderLine.
How are primary keys shown in an entity-relationship diagram?
The name of the attribute which is the primary key is underlined.
How are foreign keys shown in an entity relationship diagram?
The name of the attribute which is the foreign key is in italics.
What is normalisation?
Normalisation is a process used to come up with the best possible design for a database.
Tables should be organised so that data is not duplicated in the same table or in different tables.
The structure should allow complex queries to be made.
There are 3 stages in normalisation, called First Normal Form (1NF), Second Normal Form (2NF), and Third Normal Form (3NF).
What is First Normal Form (1NF)?
A table is in First Normal Form if it contains no repeating attributes or groups of attributes.
All attributes must be atomic – a single attribute cannot consist of 2 data items (e.g. addresses, each part must be on a separate line to be able to search by street name, postcode etc.)