One to Many

Untitled

One to One

Untitled

Many to Many

Untitled

Type Details
One to one 1 row on table A can only relate with 1 row on table B.
One to many 1 row on table A can relate with many rows on table B.

1 row from table B can only relate with 1 row from table A. | | Many to many | 1 row on table A can relate with many rows on table B.

1 row on table B can relate with many rows on table A. |

Primary Key and Foreign Key

Primary

Primary Key

Primary Key is a column that can be identifier line. The characteristic

  1. Unique: No line that has same values
  2. Not Null: No lines that has NULL in that column

Example

Untitled

Foreign

It’s a column that refers to primary key column in other table that create relationship

Untitled

Alter Table