Primary & Foreign Keys
Fields & data types
What is a field?
A field is a single piece of data in a table (column)
What is a data type?
A data type is the type of data that can be held in a field and is defined when
designing a table
Examples of common datatypes are:
o Numeric - whole/decimal
o Character/string - text data
o Date/Time
o Boolean - true or false values
In the car table above, the following datatypes would be used:
o car_id: numeric
o make: string
o model: string
o colour: string
o price: numeric
Primary Keys & Foreign Keys
What is a primary key?
A primary key is a unique field that can be used to identify a record in a table
order_id is the primary key for the orders table.
customer_id is the primary key for the customers table
What is a foreign key?
A foreign key is a field in a table that refers to the primary key in another
table.
A foreign key is used to link tables and create relationships
In the orders table customer_id is a foreign key - it links an order back to the