Yorkville High School Computer Science Department
Yorkville High School Computer Science Department on Facebook  Yorkville High School Computer Science Department Twitter Feed  Yorkville High School Computer Science Department on Instagram

Yorkville High School Computer Science

ASSIGNMENTS: Compiler Part 2 - December 3, 2018 :: Challenges 7 - December 7, 2018 :: Network App - December 14, 2018 >>

Database Programming :: Lessons :: Relational Databases

Relational Database Structure

A relation, or table, is a named collections of rows and columns of related data. It can be written as Relation_Name (A1, A2, ..., An) where each column is a named attribute. The domain of an attribute is the constraints put upon that attribute. For example, a batting average attribute would be constrained between 0 and 1 since a batting average cannot exceed 1. An attribute must also be made up of atomic values, meaning each attribute cannot store more than one item. For example, you could not store all of the classes a student takes in one attribute. In these cases you probably need another table to store the needed data. The rows of a table are also known as tuples and are similar to a record. Each row represents a unique entry in the table.

A1 A2 ... ... ... An
           
           
           

A super key is an attribute or set of attributes that uniquely identifies a tuple. A relation can have more than one super key, and every relationship has at least one super key, which is the set of all attributes.

A candidate key is a minimal super key, or a minimum set of attributes that uniquely identifies a tuple. A relation may have more than one candidate key. The primary key of a relation is the chosen candidate key of that relation. A relation can have only one primary key. You can see some key examples for the Student and Assignment examples below. Once the primary key is found, you can underline it in the written form of the relation to indicate it.

Student (Student_ID, Student_Name, Birthday, Address, Grade)

Assignment (Student_ID, Assignment_ID, Assignment_Title, Assignment_Points)

A foreign key is used to refer to another table. Attributes of a foreign key must have the same domain as the attribute in the home table. Below is a partial example of an attribute list where attributes and keys can be shown if they cannot fit on the ER diagram. Drawing the arrows in an attribute list is optional, but it can help to better show the connections between tables.

Attribute List
Created with Draw.io

A null value signifies a missing attribute value. Try to use 0 or the empty string "" when possible. You should only allow null values in the following situations:

Characteristics of a Relation

A table (relation) has order independence. This means a table is considered an unordered set and the tuples are not stored in any particular order. The attributes can also be stored in any order as long as the correspondence between the attribute and its values are maintained.

The domain integrity constraints specify the valid values of each attribute. For a "Grade" attribute in a "Student" table the valid values would be 9, 10, 11, and 12. The entity integrity constraint states that no attribute of a primary key can be null. Finally, the referential integrity constraint states that a foreign key must be null or contain a valid value of the primary key in the home table.

Yorkville High School Computer Science Department on Facebook Yorkville High School Computer Science Department Twitter Feed Yorkville High School Computer Science Department on Instagram