Hi!
I have a problem here and it is putting me NUTS.
Here is my situation:
I've two tables named "PRODUCT" and "PTYPE" and a FK constraint from
"PRODUCT" to "PTYPE" named "FK_PRODUCT_PTYPE".
PRUDUCT
id <- Primary key
name
ptype
PTYPE
id <- Primary key
description
PRODUCT.ptype FK constraint to PTYPE.id
TABLE PTYPE have 1 row
id description
-- ---------------------
A ptype B
TABLE PRODUCT have 1 row
id name ptype
-- ------------- --
P1 product P1 A
In my application I need to disable and reenable the constraint
"FK_PRODUCT_PTYPE" to make some updates to my tables.
If I execute a STORE PROCEDURE that have this statement:
- exec('update PTYPE set id=''B'' where id=''A''')
the SQL Server raise an error:
- UPDATE statement conflicted with COLUMN REFERENCE constraint
'FK_PRODUCT_PTYPE'.
The conflict occurred in database 'XXX', table 'PRODUCT', column
'PTYPE'.
until now everything is ok.
If I execute a second STORE PROCEDURE that have this statements:
- exec('alter table PRODUCT NOCHECK constraint FK_PRODUCT_PTYPE')
- exec('update PTYPE set id=''B'' where id=''A''')
- exec('alter table PRODUCT CHECK constraint FK_PRODUCT_PTYPE')
- exec('update PRODUCT set ptype=''B'' where ptype=''A''')
again it works fine. But ...
if then I execute a third STORE PROCEDURE that have this statement:
- exec('update PTYPE set id=''A'' where id=''B''')
the SQL Server DO NOT raise any error. It must raise an error because I have
a fk constraint between PRODUCT and PTYPE tables that have to be checked by
SQL SERVER, I suppose?!?!?.
What I'm doing wrong!?!?
Please help me.
Thanks in Advance,
Regards,
Mrio