Unix Technical Forum

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

This is a discussion on How to check if DB Constraints are enabled in a database? within the SQL Server forums, part of the Microsoft SQL Server category; --> How to check if DB Constraints are enabled in a database?...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 06:36 PM
sarada7@gmail.com
 
Posts: n/a
Default How to check if DB Constraints are enabled in a database?

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 06:36 PM
ZeldorBlat
 
Posts: n/a
Default Re: How to check if DB Constraints are enabled in a database?


sarada7@gmail.com wrote:
> 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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 06:36 PM
sarada7@gmail.com
 
Posts: n/a
Default Re: How to check if DB Constraints are enabled in a database?

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?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 06:36 PM
ZeldorBlat
 
Posts: n/a
Default Re: How to check if DB Constraints are enabled in a database?


sarada7@gmail.com wrote:
> 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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 06:36 PM
sarada7@gmail.com
 
Posts: n/a
Default Re: How to check if DB Constraints are enabled in a database?

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-29-2008, 06:36 PM
sarada7@gmail.com
 
Posts: n/a
Default Re: How to check if DB Constraints are enabled in a database?

sp_helpconstraint returns constraint information

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-29-2008, 06:37 PM
Erland Sommarskog
 
Posts: n/a
Default Re: How to check if DB Constraints are enabled in a database?

(sarada7@gmail.com) writes:
> 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@sommarskog.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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:12 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com