Solved

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

Posted on 2008-10-29
2
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
table joins in qry 17 82
Check ALL SP in database make sure there are no errors 17 60
Can I skip a node in XML? 9 30
sql select total by week ending 3 21
Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

740 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