1

I am using following query to get the list of all constraints of a single table in my database

sp_helpconstraint 'schema.tableName'

and then I am extracting the "Check Constraints" from the result set and using it. But as I have to run the above query every time for each table, therefore this makes my process slower. What I want is- a query in which I can get either the list of all constraints with their definition or only the List of Check Constraints for all tables of the database at once. As this will help to speed up my process in Sybase ASE

Surabhi Agarwal
  • 93
  • 2
  • 10

3 Answers3

1

Check the following

select object_name(tableid) as "table name", 
object_name(constrid) as "constraint name",
col_name(tableid,sysconstraints.colid) as "column name",
text as "constraint text"
from sysconstraints,syscomments
where sysconstraints.status=128 and sysconstraints.constrid=syscomments.id

The sysconstraints specification at http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc36274.1572/html/tables/X20320.htm explains the status=128 it means it is a check constraint

Kimon
  • 69
  • 5
1

This gives the table name as well:

select 
object_name(constid) as "Constraint name",
object_name(sysconstraints.id) as"Table name" ,
[TEXT]
from sysconstraints join syscomments on syscomments.id =sysconstraints.constid
order by [Table name]
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
-1

SELECT * FROM SYS.SYSTABLE;

SELECT * FROM SYS.SYSCOLUMN;

SELECT * FROM SYS.SYSCONSTRAINT;

SELECT * FROM SYS.SYSFOREIGNKEY;

SELECT * FROM SYS.SYSINDEX;

SELECT * FROM SYS.SYSUSERPERMS;

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 03 '22 at 01:04