10 - Fundamentals of Databases Flashcards
(34 cards)
What does it mean for relations to be in Third Normal Form.
Why is it important that the relations in a relational database are in Third Normal Form?
IGNORE (original card)
3NF means every non-key attribute is dependent on the key, the whole key and nothing but the key. There are also no repeating groups.
This is important to eliminate update anomalies, eliminate insertion anomalies, eliminate deletion anomalies, eliminate data inconsistency and minimise data duplication.
State the properties that the relations in a fully normalised database must have.
IGNORE (original card)
- There are no repeating groups of attributes.
- All non-key attributes depend on the whole key.
- All non-key attributes depend on nothing but the key.
Describe a problem when a table is not normalised.
IGNORE (original card)
It is difficult to query as it contains repeating groups of attributes.
What is the name given to a key that is made up of multiple attributes?
IGNORE (original card)
Composite key
Why is it important for a database to be in third normal form?
IGNORE (original card)
- Eliminate update anomalies
- Eliminate insertion anomalies
- Eliminate deletion anomalies
- Eliminate data inconsistency
- Eliminate data redundancy
What is a data model?
A data model is an abstract model of which things to store and what information about them should be recorded. It is created from data requirements when designing a database.
What is an entity in database design?
An entity is a thing about which data is to be stored, for example: a customer. Databases are formed of tables which are used to store multiple entities. Each entity usually has its own row in a table.
What are attributes in database design?
Attributes are characteristics or other information about entities, for example: the customer’s name or address. Fields of a table row hold the entity’s attributes.
What is an entity identifier and why is it important?
An entity identifier is an attribute given to each entity which is unique within that table. It’s important to ensure that each entity has a unique identifier when creating a database. Some database tables have multiple attributes which are combined to form the table’s entity identifier.
How do you write an entity description?
An entity description shows how information about an entity is stored in a database. Format: EntityName (Attribute1, Attribute2, Attribute3)
Example: Customer (CustomerID, CustomerName, CustomerAddress, CustomerEmail)
The entity identifier is underlined in the description.
What are the three possible degrees of relationship between tables in a relational database?
The three possible degrees of relationship between tables are:
- One-to-one: Each car has one owner, and each owner has one car
- One-to-many: Each car has many passengers. Each passenger sits in one car
- Many-to-many: Each driver can drive many different cars. Each car is driven by many different drivers
What are Entity Relationship (ER) diagrams?
Entity relationship diagrams (or ER diagrams) are used to graphically represent the relationships between tables in a database. Tables are shown as rectangles and are joined by lines which can represent different types of relationship (one-to-one, one-to-many, many-to-many).
What is a primary key?
A primary key is an attribute that provides a unique identifier for every entity in a database table. When tables are linked by a shared attribute, the attribute must be a primary key in one table.
What is a foreign key?
A foreign key is an attribute in a table which is the primary key in another, related, table. Foreign keys are used to link tables together through shared attributes.
What is a composite primary key?
A composite primary key is formed when it is not possible to create a primary key from just one attribute. Multiple attributes are combined together to form the composite primary key, ensuring uniqueness across the table.
How do you handle many-to-many relationships in relational databases?
When linking many-to-many relationships, a new table called a link table has to be created. This link table contains foreign keys from both of the related tables, allowing the many-to-many relationship to be properly represented.
Why are databases normalised?
Databases are normalised so that they can be efficient without any compromise to the integrity of their data. Benefits include:
- Faster searching and sorting thanks to smaller tables
- Easier to maintain than unnormalised databases
- Duplication of data is minimised
- Data consistency is improved
- Reduces update, insertion and deletion anomalies
What is First Normal Form (1NF)?
When a database conforms to first normal form, it contains no repeating attributes. The database’s data can be referred to as atomic (meaning that no single column contains more than one value).
Example: If a staff member teaches multiple subjects, each subject must be in a separate row, not combined in one cell.
What is Second Normal Form (2NF)?
In order to meet second normal form, a database must:
- Satisfy First Normal Form
- Remove partial key dependencies
A partial key dependency occurs in databases with composite primary keys when a non-key attribute doesn’t depend on the whole of the composite key. These dependencies must be moved to separate tables.
What is Third Normal Form (3NF)?
In order to meet third normal form, a database must:
- Conform to Second Normal Form
- Have no non-key dependencies
A database that meets third normal form can be described as: “All non-key attributes depend on the key, the whole key and nothing but the key”
What is SQL and what type of language is it?
SQL (Structured Query Language) is a language used with databases. SQL is easy to learn and use, partly because it is a declarative language, meaning that the programmer describes the result that’s required rather than describing the process which should be followed.
The four main SQL commands are: SELECT, UPDATE, INSERT and DELETE.
What is the syntax for the SELECT command in SQL?
The SELECT command is used for retrieving data from a database table:
SELECT <attribute> FROM <table> WHERE <condition> ORDER BY <ASC/DESC></condition></attribute>
Note: The ORDER BY clause is optional.
Example:
SELECT FlightNo FROM Flights WHERE Destination = ‘Berlin’
What is the syntax for the UPDATE command in SQL?
The UPDATE command is used for modifying the attributes of an existing entity:
UPDATE <table> SET <attribute> = <value> WHERE <attribute> = <value></value></attribute></value></attribute>
Example:
UPDATE Students SET Email = ‘beth24@yahoo.co.uk’ WHERE StudentNo = 55887
UPDATE commands usually use the table’s primary key to identify which entities to update but can use more general conditions.
What is the syntax for the DELETE command in SQL?
The DELETE command is used for removing entities from a database:
DELETE FROM <table> WHERE <condition></condition>
Example:
DELETE FROM Cars WHERE Sold = TRUE
This will remove all records from the Cars table where the Sold field is TRUE.