PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.sqlserver.server > Scripting Candidate key
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Scripting Candidate key

Réponse
 
LinkBack Outils de la discussion
Vieux 18/06/2008, 00h01   #1
Don
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Scripting Candidate key

Hello, I have a database with a table that had it's primary key as 3 columns,
I finally added a new column to be an idenity column but kept the original
primary key to keep things working. But when I create new tables I want to
link on my new field. By doing something like this.

ALTER TABLE [dbo].[Table2] WITH NOCHECK ADD CONSTRAINT
[fk_Table2_TableID_Table1] FOREIGN KEY([TableID])
REFERENCES [dbo].[Table1] ([TableID])
GO

But I receive this error message when doing it
There are no primary or candidate keys in the referenced table 'dbo.Table1'
that match the referencing column list in the foreign key
'fk_Table2_TableID_Table1'.

How do I make the new idenity column in my originally table a candidate key?
If you have a example in script that would be great.

Thanks

  Réponse avec citation
Vieux 18/06/2008, 03h13   #2
Dan Guzman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Scripting Candidate key

> How do I make the new idenity column in my originally table a candidate
> key?
> If you have a example in script that would be great.
>


One method is to add a UNIQUE constraint:

ALTER TABLE dbo.Table1
ADD CONSTRAINT UQ_Table1_TableID
UNIQUE(TableID);

--
Hope this s.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

"Don" <Don@discussions.microsoft.com> wrote in message
news4FD5AF0-6264-4B41-A8A6-F7DCC07D3F48@microsoft.com...
> Hello, I have a database with a table that had it's primary key as 3
> columns,
> I finally added a new column to be an idenity column but kept the original
> primary key to keep things working. But when I create new tables I want
> to
> link on my new field. By doing something like this.
>
> ALTER TABLE [dbo].[Table2] WITH NOCHECK ADD CONSTRAINT
> [fk_Table2_TableID_Table1] FOREIGN KEY([TableID])
> REFERENCES [dbo].[Table1] ([TableID])
> GO
>
> But I receive this error message when doing it
> There are no primary or candidate keys in the referenced table
> 'dbo.Table1'
> that match the referencing column list in the foreign key
> 'fk_Table2_TableID_Table1'.
>
> How do I make the new idenity column in my originally table a candidate
> key?
> If you have a example in script that would be great.
>
> Thanks
>


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h30.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,07414 seconds with 10 queries