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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for Constraints... 1

Status
Not open for further replies.

Neil Toulouse

Programmer
Joined
Mar 18, 2002
Messages
882
Location
GB
Hi there!

How can I check for the existence of a constraint on a field? And on a table?

Basically I want to create one but not bother if it already exists.

TIA
Neil

I like work. It fascinates me. I can sit and look at it for hours...
 
SELECT t.Name as Table_Name, c.Name as Column_Name, d.Name as Default_Constraints_Name, d.definition as Default_Value
FROM sys.default_constraints d
LEFT JOIN sys.tables t ON d.parent_object_id = t.object_id
LEFT JOIN sys.columns c ON t.object_id = c.object_id AND d.parent_column_id = c.column_id
 
Many thanks! Is there something similar for SQL2000?

Also can this command be adjusted to show indexes on tables?

TIA
Neil

I like work. It fascinates me. I can sit and look at it for hours...
 
This will give you what you wants:

exec sp_help 'YourTableName'
 
Excellent! That will do nicely :)

Many thanks
Neil

I like work. It fascinates me. I can sit and look at it for hours...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top