How to query constraints in Sybase

I have following query works for SQL Server. Can someone help me translate it to Sybase?
USE database_name;
GO
SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
SCHEMA_NAME(schema_id) AS SchemaName,
OBJECT_NAME(parent_object_id) AS TableName,
type_desc AS ConstraintType
FROM sys.objects
WHERE type_desc LIKE '%CONSTRAINT'
GO
HopeQAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

PortletPaulfreelancerCommented:
change 'sys.objects' to 'sysobjects'

also then look at the fieldnames, here:
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc36271_36272_36273_36274_1250/html/refman/X14933.htm

and other system tables are also documented there.

ps: don't have access to Sybase myself I'm afraid
0
PortletPaulfreelancerCommented:
This may help (untested)
SELECT
        o1.name  constraint_name
      , o2.name  table_name
      , col.name column_name
FROM sysobjects o1
INNER JOIN sysconstraints c
        ON o1.id = c.constrid
INNER JOIN sysobjects o2
        ON o2.id = c.tableid
INNER JOIN syscolumns col
        ON col.id = c.colid

Open in new window

0
Joe WoodhousePrincipal ConsultantCommented:
In fact all you need to do is look at Sybase's source code for their system stored procedures. They could easily have hidden or encrypted it and deliberately chose not to, so we could see how to write these sorts of queries.

The text of sp_helpconstraint in the sybsystemprocs database has everything you need.

It's a bit more complicated than you think because check constraints, RI constraints, and key constraints all work differently. If you want to see all of them you'll need some clever code - remember a unique index acts as a unique constraint but is not stored as a constraint...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.