[SQL Tutorial] Tables & Keys

[SQL Tutorial] Tables & Keys_第1张图片
[SQL Tutorial] Tables & Keys_第2张图片

Examples

[SQL Tutorial] Tables & Keys_第3张图片
[SQL Tutorial] Tables & Keys_第4张图片
surrogate key (a primary key with no real world meaning)
[SQL Tutorial] Tables & Keys_第5张图片
natural key (a primary key having a purpose in real world)
[SQL Tutorial] Tables & Keys_第6张图片
foreign key (a mapping from this database to another database)
[SQL Tutorial] Tables & Keys_第7张图片
foreign key defs the relationships between tables

Branch table also defines who's the manage
Scranton Branch's mgr_id = 101 => Michael Scott

[SQL Tutorial] Tables & Keys_第8张图片
supervisor id defs a mapping within a table
[SQL Tutorial] Tables & Keys_第9张图片
composite key (two attributes defing the primary key)
[SQL Tutorial] Tables & Keys_第10张图片
Works_With table uses two foreign keys as the primary key

你可能感兴趣的:([SQL Tutorial] Tables & Keys)