Question

I'm trying to set up a Sybase query that will give me the following output:

Table     KeyType      KeyNumber      Column
table1    PK           1              table1_id
table1    FK           2              table2_id    
table1    FK           3              table3_id
table1    FK           4              table4_id
table1    Unique       5              table1_abc
table1    Unique       5              table1_def

In other words, I need the PK for each table, and every foreign key it has, as well as every unique key (not where a key has more than one element, such as the unique key above, this is identified by having the same KeyNumber).

I'm guessing I need to use sysobject, syscolumns, syskeys and sysconstraints but I can't seem to figure out how they interlink.

Thanks
Karl

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top