primary key - Identifying Sybase tables, fields, keys, constraints -
i'm trying set sybase query give me 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, need pk each table, , every foreign key has, every unique key (not key has more 1 element, such unique key above, identified having same keynumber).
i'm guessing need use sysobject, syscolumns, syskeys , sysconstraints can't seem figure out how interlink.
thanks
karl
this start:
select t.name, case k.type when 1 'pk' when 2 'fk' when 3 'common' end, c.name sysobjects t inner join syscolumns c on c.id = t.id inner join syskeys k on k.id = t.id , c.colid in (k.key1, k.key2, k.key3, k.key4, k.key5, k.key6, k.key7, k.key8) t.type = 'u' , k.type in (1,2)
it not include key id, guess somehow hash non-null table id , keyn columns produce unique id key.
it not include unique indexes. want union
along lines of:
select t.name, 'unique', c.name sysobjects t inner join syscolumns c on c.id = t.id inner join sysindexes on i.id = t.id t.type = 'u'
check out sybase manual page sysindexes on how filter it.
Comments
Post a Comment