Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to Cascade FK values from VFP?
Message
 
 
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01537208
Message ID:
01537234
Vues:
18
>>>>>Am I wrong?
>>>>
>>>>I am not sure - I prefer to use BEGIN TRANSACTION myself instead.
>>>
>>>I tried that and it does not work either. That is I replaced the code of SQLSETPROP with
>>>SQLEXEX( nConnHanlde, "BEGIN TRANSACTION" ) but to no avail.
>>
>>I need to see the whole code.
>
>Here is what I just tried in SSMS but it failed. Error that this conflicts with the constraint:
>
>
>use [MyDatabase]
>go
>begin transaction
>update parent set employee = 'TEST34' where employee = 'TEST1'
>update child    set employee = 'TEST34' where employee = 'TEST1'
>commit 
>
I got the same error and it's explainable. Here is the test I just made - only after I added the setting key to NULL in the child table first it worked:
use tempdb 

create table Employee (EmpNo varchar(20) primary key, EmpName varchar(200))
insert into Employee values ('Test1','Naomi')

create table Salaries (EmpNo varchar(20), Salary money)

alter table Salaries add constraint FK_Salaries_Employee_EmpNo
foreign key (EmpNo)
references Employee (EmpNo)
insert into Salaries values ('Test1', 1000)

go
begin transaction
   update Salaries set EmpNo = NULL where EmpNo = 'Test1'
   update Employee set EmpNo = 'Test32' where EmpNo = 'Test1'
   update Salaries set EmpNo = 'Test32' where EmpNo = 'Test1'
commit transaction
You should either have CASCADE relation or set the FK value to NULL first. Otherwise it's a "catch 22" situation.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform