Chapter 8 Flashcards
What is a database?
Database is a structured collection of data that can be accessed by different applications programs. It allows efficient storage, retrieval and cross checking of data.
Data is structured as a collection of records. Each record is made up of fields, containing data about the same thing.
Flat Files:
Originally all data was stored in one table in a file.
o Very large files in size
o Difficult to process
o Difficult to modify structure (e.g. add a field)
Limitations of a file-based approach to store data:
Data redundancy // data is repeated in more than one file.
Data dependency // changes to data means changes to programs accessing that data.
Lack of data integrity // entries that should be the same can be different in different places.
Lack of data privacy // all users have access to all data if a single flat file.
Database structure:
A database contains one or more tables.
Data is stored in rows and columns;
Each row of the table is known as record.
Each column (data item) of the table is known as field.
What is an alternative to flat files?
RELATIONAL DATABASES; a database in which the
data items are linked by internal pointers.
What data types are used in a database?
A field only has 1 datatype.
Data type can be text, alphanumeric, numeric, boolean,
date/time.
Relational databases:
Relational Databases use two or more tables linked
together (to form a relationship) and do not store all the data in the same table.
Data is stored in Tables called ENTITIES.
Each record is called a TUPLE (row).
A data item is called an ATTRIBUTE (column).
Each record has a unique primary key field.
Primary key in one entity is the foreign key in another entity.
When is a relationship formed in a relational database?
It is an association between entities.
A relationship is formed when our two tables are joined together.
A relationship is formed when one table in a database has a foreign key that refers to a primary key in another table in the database.
Relationships may be mandatory(I I) or optional(o).
E-R diagrams (entity relationship):
- one-to-one (1:1)
- one-to-many (1:M)
- many-to-many (M:N)
!Many-to-many relationships should not be present when designing a relational database as they can lead to unnecessary storage of the same data more than once (duplicated) and can make it difficult to avoid errors such as update, deletion or insertion anomalies!.
What is a primary key?
Uniquely identifies each row of the entity/table.
Can be used as a foreign key in another table to form a
link.
The attribute must always contain a value for the record to be inserted into the table.
What is a secondary key?
An attribute which is used to access the data in some way other than by using the primary key.
The secondary key is not the primary key in another table.
What is a foreign key?
A set of attributes that refer to the primary key in another table.
The means by which the tables are linked together and
relationships are formed.
Referential integrity:
Makes sure that tables do not try to reference data which does not exist (a value of one attribute of a table exists as a value of another attribute in a different table).
Every foreign key value has a matching value in the corresponding primary key.
A primary key cannot be deleted unless all dependent records are already deleted → Cascading delete.
A primary key cannot be updated unless all dependent records are already updated → Cascading update / edit.
Resolving many-to-many:
It is necessary to create a third entity. The new table/entity will have two one-to-many relationships.
E-R diagram cardinality:
The type of relationship and whether it is mandatory or optional gives the cardinality.