Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-10-24 : 09:44:39
|
| mahsa writes "i encounter a problem while trying to create a foreign key!the base table has a column called "FORMSERIE DECIMAL"; this table owns a composite PK.the other table which is has the same column with the same data type; i continue to get this error message:the columns in table 'SI_FORM'do not match an existing primary key orUNIQUE constraint.can anybody tell me what my mistake is?thanks in advanceif exists (select * from dbo.sysobjects where id =object_id(N'[dbo].[SI_FORM]') and OBJECTPROPERTY(id, N'IsUserTable')= 1)drop table [dbo].[SI_FORM]GOif exists (select * from dbo.sysobjects where id =object_id(N'[dbo].[SI_PROJECT]') and OBJECTPROPERTY(id,N'IsUserTable') = 1)drop table [dbo].[SI_PROJECT]GOCREATE TABLE [dbo].[SI_FORM] ( [FORMSERIE] [decimal](18, 0) NOT NULL , [FORMTYPE] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_ASNOT NULL , [QUESTIONNUMBER] [decimal](18, 0) NOT NULL , [QUESTIONTEXT] [nvarchar] (300) COLLATESQL_Latin1_General_CP1_CI_AS NOT NULL) ON [PRIMARY]GOCREATE TABLE [dbo].[SI_PROJECT] ( [ID] [uniqueidentifier] NOT NULL , [CONSTRUCTOR] [nvarchar] (50) COLLATESQL_Latin1_General_CP1_CI_AS NULL , [PTITLE] [nvarchar] (200) COLLATESQL_Latin1_General_CP1_CI_AS NOT NULL , [SAPCOREP] [nvarchar] (50) COLLATESQL_Latin1_General_CP1_CI_AS NOT NULL , [CONSTRUCTORREP] [nvarchar] (50) COLLATESQL_Latin1_General_CP1_CI_AS NULL , [OUTLINE] [nvarchar] (300) COLLATESQL_Latin1_General_CP1_CI_AS NULL , [GOAL] [nvarchar] (300) COLLATE SQL_Latin1_General_CP1_CI_ASNULL , [FORMSERIE] [decimal](18, 0) NOT NULL) ON [PRIMARY]GO" |
|
|
mcrowley
Aged Yak Warrior
771 Posts |
Posted - 2005-10-24 : 11:14:57
|
| A foreign key must reference an entire primary or unique key in the parent table. Unfortunately, you can not reference only a part of the key. |
 |
|
|
|
|
|
|
|