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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 receive error while setting FK

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 or

UNIQUE constraint.

can anybody tell me what my mistake is?

thanks in advance





if exists (select * from dbo.sysobjects where id =

object_id(N'[dbo].[SI_FORM]') and OBJECTPROPERTY(id, N'IsUserTable')

= 1)
drop table [dbo].[SI_FORM]
GO

if exists (select * from dbo.sysobjects where id =

object_id(N'[dbo].[SI_PROJECT]') and OBJECTPROPERTY(id,

N'IsUserTable') = 1)
drop table [dbo].[SI_PROJECT]
GO

CREATE TABLE [dbo].[SI_FORM] (
[FORMSERIE] [decimal](18, 0) NOT NULL ,
[FORMTYPE] [char] (2) COLLATE SQL_Latin1_General_CP1_CI_AS

NOT NULL ,
[QUESTIONNUMBER] [decimal](18, 0) NOT NULL ,
[QUESTIONTEXT] [nvarchar] (300) COLLATE

SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[SI_PROJECT] (
[ID] [uniqueidentifier] NOT NULL ,
[CONSTRUCTOR] [nvarchar] (50) COLLATE

SQL_Latin1_General_CP1_CI_AS NULL ,
[PTITLE] [nvarchar] (200) COLLATE

SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[SAPCOREP] [nvarchar] (50) COLLATE

SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[CONSTRUCTORREP] [nvarchar] (50) COLLATE

SQL_Latin1_General_CP1_CI_AS NULL ,
[OUTLINE] [nvarchar] (300) COLLATE

SQL_Latin1_General_CP1_CI_AS NULL ,
[GOAL] [nvarchar] (300) COLLATE SQL_Latin1_General_CP1_CI_AS

NULL ,
[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.
Go to Top of Page
   

- Advertisement -