Creating Primary and Foreign Keys in SQL Server 2012
Back to learning
Created: 21/02/2015
Creating Primary and Foreign Keys in SQL Server 2012
Nice tutorial to understand what is and how to use fireign key in Sql
Another example: (Many tracks (FK) -> in one Album(PK))
CREATE TABLE album(
id CHAR(10) NOT NULL PRIMARY KEY,
title VARCHAR(100),
artist VARCHAR(100)
);
CREATE TABLE track(
album CHAR(10),
dsk INTEGER,
posn INTEGER,
song VARCHAR(255),
FOREIGN KEY (album) REFERENCES album(id)
);