Results 1 to 2 of 2
  1. #1
    Join Date
    May 2009

    Unanswered: SQL statement - help


    Sorry for my english. Im a new in sybase. Im using sybase 10.0.1.

    I need to write such SQL statement which returns the name of foreign key COLUMN name. I know only primary and foreign table names.

    Example: i have two tables Reiksmes and Temp. Where = temp.fk_reiksmes. So i need that SQL return me foreign table, foreign key, column name - fk_reiksmes.

    I tried such a thing:

    select columns from sysforeignkeys where foreign_tname = 'temp' and primary_tname = 'reiksmes'

    but it returned such thing:
    'fk_reiksmes IS id'

    this is not good, becouse after i need to split this string by space etc...

    Who can help me? Thank you.

  2. #2
    Join Date
    Mar 2007
    Interesting question ..this should get you started .. have fun (btw uid ==1 is 'dbo')

    select object_name(r.tableid) referencingTable,
    object_name(r.reftabid) as referencedTable, r.keycnt, col_name(r.reftabid,r.refkey1) as colName,
    object_name(r.constrid), r.constrid fkeyConstraintName,
    col_name(r.tableid,r.fokey1) as key1, col_name(r.tableid,r.fokey2) as key2,
    col_name(r.tableid,r.fokey3) as key3, col_name(r.tableid,r.fokey4) as key4,
    col_name(r.tableid,r.fokey5) as key5, col_name(r.tableid,r.fokey6) as key6,
    col_name(r.tableid,r.fokey7) as key7, col_name(r.tableid,r.fokey8) as key8,
    col_name(r.tableid,r.fokey9) as key9, col_name(r.tableid,r.fokey10) as key10,
    col_name(r.tableid,r.fokey11) as key11, col_name(r.tableid,r.fokey12) as key12,
    col_name(r.tableid,r.fokey13) as key13, col_name(r.tableid,r.fokey14) as key14,
    col_name(r.tableid,r.fokey15) as key15, col_name(r.tableid,r.fokey16) as key16
    from sysreferences r, sysobjects o
    where r.constrid = and o.uid = 1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts