the syntax is
ALTER TABLE tablename WITH NOCHECK ADD Constraint.
Main Topics
Browse All TopicsDear all,
I am in process of testing installation scripts, and have a problem creating a foreign key constraint with "no check" against it. The following is a snippet from my foreign key constraint building script:
ALTER TABLE [dbo].[product_mailing_reg
CONSTRAINT [FK_product_mailing_region
(
[product_id]
) REFERENCES [dbo].[product] (
[product_id]
),
CONSTRAINT [FK_product_mailing_region
(
[region_id]
) REFERENCES [dbo].[region] (
[region_id]
),
CONSTRAINT [FK_product_mailing_region
(
[mailing_type_id]
) REFERENCES [dbo].[mailing_type] (
[mailing_type_id]
) NOT FOR REPLICATION
GO
alter table [dbo].[product_mailing_reg
GO
Now this works fine if there is no data in the database, but it cannot create FK_product_mailing_region_
Best Regards,
- Graham
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Great, thanks, I've adjusted to:
ALTER TABLE [dbo].[product_mailing_reg
CONSTRAINT [FK_product_mailing_region
(
[product_id]
) REFERENCES [dbo].[product] (
[product_id]
),
CONSTRAINT [FK_product_mailing_region
(
[region_id]
) REFERENCES [dbo].[region] (
[region_id]
)
GO
ALTER TABLE [dbo].[product_mailing_reg
CONSTRAINT [FK_product_mailing_region
(
[mailing_type_id]
) REFERENCES [dbo].[mailing_type] (
[mailing_type_id]
) NOT FOR REPLICATION
GO
So that the NOCHECK only applies to the correct FK constraint. However, the previous syntax also seemed to disable "Enforce relationship for INSERTs and UPDATEs", whereas the new syntax doesn't. How can this be added to the script?
Yes, the difficulty is having data in there with the value of zero (instead of null) due to the .asp code being designed for multiple database engines and having trouble referencing null in some of them (I forget which, it's probably a legacy problem now anyway).
It's not too much of a hassle, as I can fire the:
alter table [dbo].[product_mailing_reg
GO
script afterwards anyway, it just seemed odd that they didn't actually set it up in the same way.
So I'm guessing that this is the route I'll have to take to achieve this ?
Business Accounts
Answer for Membership
by: NightmanPosted on 2007-02-09 at 04:46:32ID: 18500788
ALTER TABLE [dbo].[product_mailing_reg ion] WITH NOCHECK ADD _product] FOREIGN KEY _region] FOREIGN KEY _mailing_t ype] FOREIGN KEY
CONSTRAINT [FK_product_mailing_region
(
[product_id]
) REFERENCES [dbo].[product] (
[product_id]
),
CONSTRAINT [FK_product_mailing_region
(
[region_id]
) REFERENCES [dbo].[region] (
[region_id]
),
CONSTRAINT [FK_product_mailing_region
(
[mailing_type_id]
) REFERENCES [dbo].[mailing_type] (
[mailing_type_id]
) NOT FOR REPLICATION
GO