Wednesday, October 20, 2010

View all constraint of table in SQL Server.

Query is to view all constraints of the table in SQL Server.

 

 

SELECT * FROM (

Select SysObjects.[Name] As [Contraint Name] ,Tab.[Name] as [Table Name],Col.[Name] As [Column Name]

 From SysObjects Inner Join (Select [Name],[ID] From SysObjects Where XType = 'U') As Tab

On Tab.[ID] = Sysobjects.[Parent_Obj]

Inner Join sysconstraints On sysconstraints.Constid = Sysobjects.[ID]

Inner Join SysColumns Col On Col.[ColID] = sysconstraints.[ColID] And Col.[ID] = Tab.[ID]

 ) A WHERE A.[TABLE NAME]='TABLENAME'

 

 

 

Thanks,

Siddu

 

P Please consider the environment before printing this e-mail

 

 

No comments:

Post a Comment

Code Formater

Paste Here Your Source Code
Source Code Formatting Options
1) Convert Tab into Space :
2) Need Line Code Numbering :
3) Remove blank lines :
4) Embeded styles / Stylesheet :
5) Code Block Width :
6) Code Block Height :
7) Alternative Background :
Copy Formatted Source Code
 
Preview Of Formatted Code