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 > comp.db.ms-sqlserver > Cascade update to two fields in a table...
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Cascade update to two fields in a table...

Réponse
 
LinkBack Outils de la discussion
Vieux 29/12/2007, 20h43   #1
Matthew Wells
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Cascade update to two fields in a table...

Hello,

I'm sure this has come up for people before. I have two fields in one
table that both refer to my users table.

TakenByID
EnteredByID

Both of these refer to UserName in tblUsers. I am trying to set up
relationships for the two fields. I made one for EnteredByID with no
problem, but I get an error when I try to set one to TakenByID. I tried
doing it in the opposite order as well (knowing this wouldn't work) and got
the same error.

ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]ALTER TABLE
statement conflicted with COLUMN FOREIGN KEY constraint
'rel_tblPatients_tblUsers'. The conflict occurred in database 'dbname',
table 'tblUsers', column 'UserLoginName'.

Here's the statement generated:

ALTER TABLE dbo.tblPatients ADD CONSTRAINT
rel_tblPatients_tblUsers FOREIGN KEY
(
EnteredByID
) REFERENCES dbo.tblUsers
(
UserName
) ON UPDATE CASCADE

GO

Why won't this work in SQL Server? I have no problem in Access.

Thanks.

Matthew Wells
Matthew.Wells@FirstByte.net


  Réponse avec citation
Vieux 29/12/2007, 23h34   #2
Erland Sommarskog
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Cascade update to two fields in a table...

Matthew Wells (Matthew.Wells@FirstByte.net) writes:
> I'm sure this has come up for people before. I have two fields in one
> table that both refer to my users table.
>
> TakenByID
> EnteredByID
>
> Both of these refer to UserName in tblUsers. I am trying to set up
> relationships for the two fields. I made one for EnteredByID with no
> problem, but I get an error when I try to set one to TakenByID. I tried
> doing it in the opposite order as well (knowing this wouldn't work) and
> got the same error.
>
> ODBC error: [Microsoft][ODBC SQL Server Driver][SQL Server]ALTER TABLE
> statement conflicted with COLUMN FOREIGN KEY constraint
> 'rel_tblPatients_tblUsers'. The conflict occurred in database 'dbname',
> table 'tblUsers', column 'UserLoginName'.


That particular message means that you have data that violates the
constraint.

But if you have two FK columns that refers to the same base table,
you cannot set up cascading foreing keys, I think. There are tons of
restrictions on when you can use ON CASCADE. The SQL Server developers
took a very conservative approach when they added cascading DRI to
SQL Server.



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
  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 22h34.


É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,08718 seconds with 10 queries