Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you refer a field which is a part of a composite primary key

Status
Not open for further replies.

database1

Technical User
May 15, 2000
8
IN
The sequence follows like this:<br>1. create table integer(a int,b int,primary key(a,b))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&gt;&nbsp;&nbsp;a table is created with both fields as composite primary<br>2. create table referinteger(a int references integer(a))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&gt; the aim was to create a table with one of the field refering to a field in another table which is composite primary.<br>But it throws error,<br>please find a solution.<br><br>
 
Hi,<br><br>It is not possible to reference a part of composite primary key.because a foreign key can created only if referenced column is unique or a primary key.<br>so if you want to reference a part of composite key ,you should have unique constraint on it or you have to reference whole part of composite primary key.<br><br>bye <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gummadi
 
2. create table referinteger(a int references integer(a<b><font color=red>, b</font></b>)) <p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br>
 
Hi,<br>I tried to apply<br>2)create table referinteger(a int references integer(a, b))<br>after creating <br>1)create table integer(a int,b int,primary key(a,b)) <br>i am getting an below error<br><br>Server: Msg 8140, Level 16, State 1, Line 1<br>More than one key specified in column level FOREIGN KEY constraint, table 'referinteger'.<br><br>Gummadi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top