How to create table with combo primary key which are also two foreign keys
Posted on 2008-10-29
I'm creating a bridge table to change a many to many relationship to two many to one relationships.
I'm new to transact-sql. The create table statement below references two columns for the primary key, au_id and title_id. These are also both primary keys in two other tables, called authors and titles. I'm not sure I have the syntax correct below. Any suggestions, oberservations are appreciated.
create table titleauthor (
au_id VARCHAR (7) NOT NULL,
title_id VARCHAR (7) NOT NULL,
PRIMARY KEY (au_id,title_id),
FOREIGN KEY (au_id,title_id) REFERENCES authors,titles);