Relational Database
A relational database is a collection of tables, way of structuring and storing information in forms of tables, rows and columns and links tables together by joining them.
Each table has a name and we refer tables as relation, we use tuple to refer to a row in the table and attribute to the columns.
Relational Databases and Consistency
A relational database consists of a relational database schema ⟨ρ,Σ⟩⟨ρ, Σ⟩⟨ρ,Σ⟩ and an instance DBDBDB of its signature ρρρ. The relational database is consistent if and only if, for any integrity constraint and any valuation : DB,θ⊨φ
Keys
Describes how a tuple in a table must be distinguished. How to tell them apart. Expressed in terms of their attributes. No tuple can have all their attributes be the same.
Primary Key Uniquely identifies each row in a table
- Chosen by the one who designed the database as a mean to identify different tuples in a table Uniqueness
- they must be chosen with care
- a lot of people can have the same name
- social security number can be a good primary key for a country
- The primary key should be chosen such that its attribute values are never, or are very rarely, changed.
Foreign key Establishes relationships between tables by referencing the primary key of another table.
- A column or combination of column in a table that establishes a link or relationship between that table and another table.
- Represent a reference to the primary key of another table allowing for the creation of relationships or associations between the two tables.
- Enables actions like joins to retrieve related data from multiple table and ensure data consistency.
Properties
- The extension of any relation in a signature should be finite
- Queries should be safe, their answers should be finite when database instances are finite. same goes to Relational Calculus