473,657 Members | 2,540 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

QUESTION: Status column of FK Constraints in sysobjects - ????

DW
Greetings:

I have to do a one-off forceful change of some data in a database. I
need to disable some FK constraints, make the data change, and then
re-enable the constraints.

My process will be:

ALTER TABLE TABLE1 NOCHECK CONSTRAINT FK_TABLE1_TABLE 2
UPDATE TABLE1 SET COLUMN1=2 WHERE COLUMN2='Proble m row'
ALTER TABLE TABLE1 CHECK CONSTRAINT FK_TABLE1_TABLE 2

I wanted to get some evidence that the constraints were back up after I
did the 'check constraint' statements, so I looked in sysobjects.
There's a status column for the constraints, but I can't make much
sense of the numbers. Most of the FK constraints that I have not
changed are of status 0, but when I NOCHECK a constraint, it goes to
2304. When I CHECK it again, it's 2408.

Can someone explain this, and suggest a way to double-check that my
constraints are in fact enabled once I run the CHECK statement?

Thanks!!

Jul 23 '05 #1
2 5755
DW (dw*******@shaw .ca) writes:
I have to do a one-off forceful change of some data in a database. I
need to disable some FK constraints, make the data change, and then
re-enable the constraints.

My process will be:

ALTER TABLE TABLE1 NOCHECK CONSTRAINT FK_TABLE1_TABLE 2
UPDATE TABLE1 SET COLUMN1=2 WHERE COLUMN2='Proble m row'
ALTER TABLE TABLE1 CHECK CONSTRAINT FK_TABLE1_TABLE 2

I wanted to get some evidence that the constraints were back up after I
did the 'check constraint' statements, so I looked in sysobjects.
There's a status column for the constraints, but I can't make much
sense of the numbers. Most of the FK constraints that I have not
changed are of status 0, but when I NOCHECK a constraint, it goes to
2304. When I CHECK it again, it's 2408.


This is because there are two status bits involved here. But rather
than looking at status bits, use the function Objectproperty( ) instead.
There are two property that applies to constraints: CnstIsDisabled
and CnstIsNotTruste d. (For the exaxt names, please look them up in
Books Online.)

If you like above, CnstIsDisabled will go back to, but CnstIsNotTruste d
will remain 1. This is because you when you re-enable a constraint,
WITH NOCHECK is the default. That is, this:

ALTER TABLE TABLE1 CHECK CONSTRAINT FK_TABLE1_TABLE 2

is equvivalent with:

ALTER TABLE TABLE1 WITH NOCHECK CHECK CONSTRAINT FK_TABLE1_TABLE 2

WITH NOCHECK means that the constraint is re-enabled without testing.
The advantages is that reapplying is fast - and if that data you sneaked
in violates the constraint, it is not trapped. But there is a downside.
"Not trusted", means that as far as the optimizer is concerned, the
constraint does not exist. This may have no impact on performance at all,
or it may be a disaster. One typical case of the latter is the
partitioning CHECK constraint for a partioned view.

Generally, I would advice of adding data that violates constraints in
a database. The optimizer knows that the constraint is not to be
trusted, but a programmer who looks at the data model, may assume that
the constraint is valid.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #2
DW
Hmm. The data change won't be violated, but just to be sure, I used

ALTER TABLE TABLE1 WITH CHECK CHECK CONSTRAINT FK_TABLE1_TABLE 2

It took a little longer, which would be explained by it checking the
existing data.

But, after re-enabling the constraints, I ran
SELECT NAME, OBJECTPROPERTY (ID, 'CNSTISDISABLED ') FROM SYSOBJECTS
WHERE NAME LIKE 'FK%'

and
SELECT NAME, OBJECTPROPERTY (ID, 'CNSTISNOTTRUST ED') FROM SYSOBJECTS
WHERE NAME LIKE 'FK%'

And the results came back with all 0's.

Thanks for that! I likely would not have reenabled these things
properly otherwise.

DW

Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
7397
by: dayong | last post by:
i need to alter all foreign keys in my database and uncheck the "Enforce relationship for replication" check box. Using the EM, I extracted the code snippet below. unfortunately, when i run this test from query analyzer, then go back into the EM, the box is still checked. can anyone tell me what i am missing? any advice on unsetting this attribute globally would be appreciated! BEGIN TRANSACTION
3
10774
by: Dave Sisk | last post by:
Hi Folks: I'm a little new to SQLServer, so please pardon my ignorance! I've found the INFORMATION_SCHEMA views for TABLES, COLUMNS, and TABLE_CONSTRAINTS. I'm looking for the views that will give me the list of columns by constraint. For instance, if Table1 has a unique key called Table1_UK01, I can find that under INFORMATION_SCHEMA.TABLE_CONSTRAINTS. But I also need to know the
1
2009
by: Poted | last post by:
I must increase column (filed) size in existing datebase but without using Enterprise manager....(Becouse we use MSDE on our clients PCs) The Filed is part of primary and foreign key constraints.... And every constraint has diferent index number in each database... for example (PK_something_9e382hjl8), and I don't know how to pick this value before "drop constraint" command..... Thank you very much....
5
4451
by: Sue | last post by:
I wrote a script that uses the sp_refreshviews. The script will be part of a larger one that is automatically run in multiple databases where different views exist. Question: My understanding of views is that by simply stating 'select * from myviewname where 0=1' that the view is recompiled. If so, what advantages are there in using sp_refreshviews? I couldn't handle the errors that sp_refreshview produced (I am sure due to my lack...
16
43349
by: bika | last post by:
I have a table that has values as follows: PersonID Degree 55 MD 55 Phd 55 RN 60 MD 60 Phd I need a create a query that will give me output like this:
6
19596
by: sarada7 | last post by:
How to check if DB Constraints are enabled in a database?
0
1277
by: ymcj | last post by:
Hi, I'm trying to change the column name - date to Sdate in all the tables in my database. As i have many to change so i tried to search all tables and have it change automatically rather than manually however my query doesn't seem to do the job? requesting assistance from anyone is appreciated thank you! DECLARE @sSQL AS VarChar(500), -- SQL Statement @sTableName AS VarChar(100) -- TableName DECLARE CursorTable CURSOR FOR...
3
18734
by: ymcj | last post by:
Hi, I'm trying to change the column name - date to Sdate in all the tables in my database. As i have many to change so i tried to search all tables and have it change automatically rather than manually however my query doesn't seem to do the job? requesting assistance from anyone is appreciated thank you! DECLARE @sSQL AS VarChar(500), -- SQL Statement @sTableName AS VarChar(100) -- TableName DECLARE CursorTable CURSOR FOR SELECT FROM...
3
4834
by: Shestine | last post by:
I am trying to add a column to a current table, with data in it. I am only learning, and i have no idea how to change this to make it work. Here is the script I have right now it, but what it does is delete the whole table and recreates it, adding in the extra column. I don't want that. I want the data that is currently there to stay there and then add anew column. How do I reword this (If possible) to make it work? if exists (select * from...
0
8425
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8326
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.