Solved

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

Posted on 2008-10-29
2
165 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 125 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

896 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now