Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Foreign Key Using Multiple Fields
Message
From
22/02/2001 10:37:29
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Foreign Key Using Multiple Fields
Miscellaneous
Thread ID:
00478423
Message ID:
00478423
Views:
68
I am trying to set up a foreign key between two tables A and B. Table A has a primary key called PKey CHAR(28). I am trying to take three fields from Table B (call them Field1 CHAR(4), Field2 CHAR(3), and Field3 CHAR(21)) and create a foreign key to Table A. I try to do this in the Diagram Tool and I keep getting errors because it is trying to match on the first field instead of all three (even though I have all three selected.)

IN Query Analyzer I use the Alter Table command below:

ALTER TABLE [dbo].[TableB] ADD
CONSTRAINT [FK_Greg] FOREIGN KEY
(
[Field1], [Field2], [Field3]
) REFERENCES [dbo].[TableA] (
[PKEY]
)

and get the following error:

Number of referencing columns in foreign key differs from number of referenced columns, table 'dbo.TableB'.


Can you tell me if what I am trying to do can be done and if so, how.
Thank You.
Next
Reply
Map
View

Click here to load this message in the networking platform