Geeks With Blogs

News Copyright © 2008-2013 Paula DiTallo
Ask Paula! ...bringing you notes from the field...

This one will order the contraints by table:

 

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]
order by Tab.[Name]

 

This one will order the contraints by column:

 

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]
order by Col.[Name]

Posted on Friday, November 5, 2010 11:36 AM Practical Answers , SQL | Back to top


Comments on this post: In SQL Server, How Do I List all the Constraints by Table or by Column Name?

# re: In SQL Server, How Do I List all the Constraints by Table or by Column Name?
Requesting Gravatar...
Thanks a lot.. your post helped me alot.. :)

Thank you so much..
Left by kishore on Sep 17, 2013 6:55 AM

Your comment:
 (will show your gravatar)
 


Copyright © Paula DiTallo | Powered by: GeeksWithBlogs.net | Join free