dbTalk Databases Forums  

How to check if DB Constraints are enabled in a database?

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss How to check if DB Constraints are enabled in a database? in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
sarada7@gmail.com
 
Posts: n/a

Default How to check if DB Constraints are enabled in a database? - 03-06-2006 , 09:50 AM






How to check if DB Constraints are enabled in a database?


Reply With Quote
  #2  
Old   
ZeldorBlat
 
Posts: n/a

Default Re: How to check if DB Constraints are enabled in a database? - 03-06-2006 , 10:35 AM







sarada7 (AT) gmail (DOT) com wrote:
Quote:
How to check if DB Constraints are enabled in a database?
What kind of constraints? Foreign key constraints? Check constraints?
They really can't be "enabled" or "disabled." Either they exist or
they don't.



Reply With Quote
  #3  
Old   
sarada7@gmail.com
 
Posts: n/a

Default Re: How to check if DB Constraints are enabled in a database? - 03-06-2006 , 10:51 AM



Yes, you are right constraints exist or they don't. My question was is
there any way to verify if any check is existing on a table before
enabling one?

For example, we add a constraint using the following SQL

ALTER TABLE Customers CHECK CONSTRAINT ALL

and disable them using

ALTER TABLE Customers NOCHECK CONSTRAINT ALL

If we run the SQL to disable the constraint. At this point how to
verify if the constraint is not existing?


Reply With Quote
  #4  
Old   
ZeldorBlat
 
Posts: n/a

Default Re: How to check if DB Constraints are enabled in a database? - 03-06-2006 , 11:13 AM




sarada7 (AT) gmail (DOT) com wrote:
Quote:
Yes, you are right constraints exist or they don't. My question was is
there any way to verify if any check is existing on a table before
enabling one?

For example, we add a constraint using the following SQL

ALTER TABLE Customers CHECK CONSTRAINT ALL

and disable them using

ALTER TABLE Customers NOCHECK CONSTRAINT ALL

If we run the SQL to disable the constraint. At this point how to
verify if the constraint is not existing?
Do something that violates the constraint and see if the server
complains.



Reply With Quote
  #5  
Old   
sarada7@gmail.com
 
Posts: n/a

Default Re: How to check if DB Constraints are enabled in a database? - 03-06-2006 , 11:27 AM



Thanks ZeldorBlat for your reply,

Other than violating the constraint and catching it, is there any
supported command which check this directly.

Thanks in advance


Reply With Quote
  #6  
Old   
sarada7@gmail.com
 
Posts: n/a

Default Re: How to check if DB Constraints are enabled in a database? - 03-06-2006 , 02:30 PM



sp_helpconstraint returns constraint information


Reply With Quote
  #7  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: How to check if DB Constraints are enabled in a database? - 03-07-2006 , 05:16 PM



(sarada7 (AT) gmail (DOT) com) writes:
Quote:
How to check if DB Constraints are enabled in a database?
SELECT name, tbl = object_name(parent_obj)
FROM sysobjects
WHERE objectproperty(id, 'CnstIsDisabled') = 1

SELECT name, tbl = object_name(parent_obj)
FROM sysobjects
WHERE objectproperty(id, 'CnstIsNotTrusted') = 1

The latter returns constraints that are enabled, but that were enabled
WITH NOCHECK, that is without checking whether the current data was
valid. The optimizer only ignores constraints that are not trusted, and
this can have serious performance impacts, particular with partitioned
views.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.