02 - Relational Databases Flashcards
What are:
Attributes?
Columns. Allowed data (e.g. INT, STRING, etc) in an attribute is called attribute domain.
What are:
Tuples?
records. A record in a table is a row, with the same number of attributes (columns). Important: Each tuple within a table needs to be unique as required by the relational model.
What are: Schema?
(meta-data) - Specification of how data is to be structured logically, defined at setup, rarely change. E.g. Student (SID int, name string, age int, gpa real)
What are: Instance?
Content of a table, changes rapidly, but always conforms to the schema.
What is a key?
a set of one or more attributes (columns) in the table that have certain properties.
Explain: Compound key?
Including two or more attributes
Explain: Superkey?
No two tuples have the same values. Key attributes that can uniquely identify a row. Several super keys can present in a table.
Explain: Candidate key?
It’s a minimum super key. A super key reduced to the least amount of attributes needed to uniquely identify a row.
Explain: Primary key?
Used to uniquely identify of find the tuples in a table, every tuple in a relational database has its own primary key. Normally it will be chosen from one of the primary keys.
Explain: Secondary Key?
Used to look up tuples, not uniqueness
Explain: Foreign Key?
used as constraint
What is an index?
database structure, quicker and easier to find tuples based on values in one or more attributes. Not the same as key.
What are: Constraints?
Related to a particular attribute in a table. Constraints are the rules enforced on the data columns of a table. These are used to limit the type of data that can go into a table.
Attribute required. Special value null represents an empty value.
Explain: Primary Key Constraints?
Entity integrity. No two records can have identical values for the primary key attribute of a table. All of the attributes that make up the primary key have non-null values.
Explain: Foreign Key Constraints?
Foreign key: refer to a key in another table. Referential integrity constraint. A tuples’ value in one or more attributes in one table must match the values in another table.
DB Operations: Selection?
Select some or all of the tuples in a table. Ex. Select only the students tuples where their gpa is greater than 2.5.
DB Operations: Projection?
Drops attributes from a table. Ex. list only students name and not their ages.
DB Operations: Union?
Combines tables with similar columns and removes duplicates.
DB Operations: Intersection?
Finds the records that are the same in two tables.
DB Operations: Difference?
Selects the tuples in one table that are not in a second table
DB Operations: Cartesian Product?
Creates a new table containing every tuples in a first table combined with every tuples in a second table.
DB Operations: Join?
Tuples in one table are paired only with those in the second table if they meet some conditions. Similar to cartesian product.
Ex: Student <-> Enroll = {(Rian, COMP40110), (Rian,COMP40120), (Alfie,COMP40120), (Alfie,COMP41430),…}
DB Operations: Divide?
Opposite of the Cartesian product. Uses one table to partition the tuples in another table.
How can you make DB retrevial faster?
keys & indexing
What are the three main vital things in DB design?
- Inclusion of all information
- Selection of correct data types
- Creation of keys / indexes
What is Database Normalisation?
Normalisation is the process of efficiently organising data in a database. There are two goals of the normalisation process:
- Eliminating redundant data (storing the same data in multiple tables)
- Ensuring data dependencies make sense (only storing related data in a table)
What are the Normal Forms (NFs)?
Strictly speaking there are seven normal forms (0NF through 5NF and BCNF). We will only look at 1NF to 3NF. As a rule databases are designed using 3NF. Very occasionally a database will be designed to 4NF.
Explain: First Normal Form (1NF)?
1NF gives the most basic rules for organising information in a DB.
- Eliminate duplicate fields from the same table
- Create separate tables for each group of related data
- Identify each row with a unique value (primary key)
Explain: Second Normal Form (2NF)?
Second Normal form removes more duplicate information:
- There must not be any partial dependency of any column on primary key
The guidelines are:
- Meet 1NF requirements
- Remove subsets of data that apply to multiple rows of a table and place them in separate tables.
- Create relationships between these new tables and their predecessors (foreign keys)
Explain: Third Normal Form (3NF)?
3NF has the following requirements:
- Meet all 2NF requirements
- Remove fields that are not dependent upon the primary key
- In third normal form every field should be dependent on the key.
What is the general naming of common database operations?
- Selection
- Projection
- Union
- Intersection
- Difference
- Cartesian Product
- Join
- Divide