Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Displaying constraints from tables

Author  Topic 

Brent555
Starting Member

10 Posts

Posted - 2006-05-12 : 00:08:47
hey i was just wondering how to display the constraints from a particular table and display all the constraints and wat columns they apply to, someone told me they keyword u use but didnt tell me how to use it :P

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-12 : 00:18:41
[code]select c.name as column_name, object_name(constid) as constraint_name
from syscolumns c inner join sysconstraints s
on c.id = s.id
and c.colid = s.colid
where c.id = object_id('table_name')[/code]


KH

Go to Top of Page

Brent555
Starting Member

10 Posts

Posted - 2006-05-12 : 00:29:21
well i dont totally understand :P but im sure ill get it :P
thnx
Go to Top of Page

Brent555
Starting Member

10 Posts

Posted - 2006-05-12 : 00:44:03
nah i cant get it, Its only displaying 1 constraint
wat i wanna do is display all the constraints that act on two particular tables aswell as the type and i wanna display the column names that are being acted upon by all constraints over all the tables,

maybe u can explain it to me
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-05-12 : 02:23:13
table sysconstraints contains constraints of an object. For type of constraints, refer to Books On Line on sysconstraints.
column status will identify the type
quote:
Bitmap indicating the status. Possible values include:
1 = PRIMARY KEY constraint.
2 = UNIQUE KEY constraint.
3 = FOREIGN KEY constraint.
4 = CHECK constraint.
5 = DEFAULT constraint.
16 = Column-level constraint.
32 = Table-level constraint.




KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-05-12 : 02:36:25
Also refer INFORMATION_SCHEMA.TABLE_CONSTRAINTS view

select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where table_name='yourTable'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -