Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8853607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:41:40+00:00 2026-06-14T13:41:40+00:00

I have a Visual Studio database project with a series of tables that have

  • 0

I have a Visual Studio database project with a series of tables that have foreign key constraints.

The publish script includes the add constraint script:

ALTER TABLE [dbo].[AttributeValue] WITH NOCHECK
ADD CONSTRAINT [FK_AttributeValue_Attribute] 
FOREIGN KEY ([AttributeId]) REFERENCES [dbo].[Attribute] ([AttributeId]);

And right at the end of the script it enabled the constraint:

ALTER TABLE [dbo].[AttributeValue] WITH CHECK CHECK CONSTRAINT [FK_AttributeValue_Attribute];

The problem is, it fails to enable the constraint because it thinks it doesn’t exist. If I check the table I can confirm it doesn’t exist.

Why has the constraint not been created?

If I run the scripts in isolation, the create works and the enable works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:41:41+00:00Added an answer on June 14, 2026 at 1:41 pm

    This really is going to be an entry for the daily WTF.

    Someone has added a post-build script to the project, which performs the following steps.

    1. DROPS all constraints by inspecting the system tables

    2. Adds some data

    3. Attempts to CREATE the constraints again by inspecting the system tables

    Of course, step 3 does nothing because there is nothing to find in the system tables, given that it removed everything in step 1.

    I am truly stunned by this plan and will replace it with the following:

    Step 1

    EXEC sp_MSforeachtable @command1="print 'Disabling constraints: ?'", @command2="ALTER TABLE ? NOCHECK CONSTRAINT all"
    

    Step 3

    EXEC sp_MSforeachtable @command1="print 'Enabling constraints: ?'", @command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database project in Visual Studio 2010 that deploys tables and stored
I have a database project in visual studio (2008) that I am using to
I have a visual studio 2008 database project that is under version control (git).
We have a post deployment script in our visual studio database project. It populates
We have a database project in Visual Studio 2008 that has been working great.
I have database project in visual studio 2010. It has tables views stored procedures
I have a development database that re-deploy frequently from a Visual Studio Database project
I have an SQL 2008 database project in Visual Studio 2010 that is sync'ed
I have a build-definition in TFS that builds a database-project in Visual Studio. The
I have a database project (.dbp) open in Visual Studio 2008 as part of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.