title: SQL Server 2008- Get table constraints
body: <p>Could you help me frame a query that retrieves the constraints in all the tables, the count of constraints in each table, and also display <code>NULL</code> for tables that do NOT have any constraints.</p>
  <p>This is what I have so far:</p>
  <pre><code>Select  SysObjects.[Name] As [Constraint Name] ,
          Tab.[Name] as [Table Name],
          Col.[Name] As [Column Name]
  From SysObjects Inner Join 
  (Select [Name],[ID] From SysObjects) 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] 
  </code></pre>