Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to create table with combo primary key which are also two foreign keys

Posted on 2008-10-29
2
Medium Priority
?
173 Views
Last Modified: 2012-06-27
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,
royalty FLOAT,
notes TEXT,
PRIMARY KEY (au_id,title_id),
FOREIGN KEY (au_id,title_id) REFERENCES authors,titles);
0
Comment
Question by:chuckmullins
2 Comments
 
LVL 37

Accepted Solution

by:
momi_sabag earned 500 total points
ID: 22829041
try
create table titleauthor (
au_id VARCHAR (7) NOT NULL,
title_id VARCHAR (7) NOT NULL,
royalty FLOAT,
notes TEXT,
PRIMARY KEY (au_id,title_id),
FOREIGN KEY (au_id) REFERENCES authors,
FOREIGN KEY (title_id) REFERENCES titles);
0
 

Author Closing Comment

by:chuckmullins
ID: 31511068
Perfect!  Thanks so much!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question