Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sysobjects question

Status
Not open for further replies.

TitleistDBA

IS-IT--Management
Apr 22, 2002
162
US
I'm look to see if any of my Foreign Key constraints have been disabled. Is there an easy way to do this?
I have run the following select which will show my all my FK constraints.
select * from sysobjects
where xtype = 'F'
How can I tell if any have been disabled with the following syntax.
ALTER TABLE cnst_example NOCHECK CONSTRAINT salary_cap
Thanks

 
By using the OBJECTPROPERTY function.
Code:
select OBJECTPROPERTY(object_id('FK_Orders_Customers'), 'CnstIsDisabled')
Where FK_Orders_Customers is the name of the key.

If you run this in Northwind it will return 0 (Enabled).

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Mr Denny.
Thank you very much. the only problem I have is there are hundreds of FK's and I don't know which one could be disabled. The company which provided us this product also gave the developers a script to disable all constraints. Why they would do that I have no idea. Anyway, I am trying to write a script to go through all the constaints and check the CnstIsDisabled property.



DECLARE @object sysname,
@cmd varchar(500)

CREATE TABLE ##TMP(name sysname null,
chk int null)

INSERT INTO ##TMP(name, chk)
SELECT name, 0
FROM sysobjects
WHERE xtype = 'F'

While @@rowcount > 0
Set rowcount 1
select @object = name
from ##TMP
where chk = 0

SELECT @cmd = 'select OBJECTPROPERTY(object_id('+ @object+'), "CnstIsDisabled")'

exec @cmd

update ##TMP
SET chk = 1
WHERE name = @object

When I run this script I get the following error.

(13 row(s) affected)

Server: Msg 203, Level 16, State 2, Line 21
The name 'select OBJECTPROPERTY(object_id(FK_Orders_Customers), "CnstIsDisabled")' is not a valid identifier.

I think it has something to do with the quotes. Any suggestions.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top