How to get List of forieng Key column name

  • Hi,

    For Eg,

    This is table structure,

    Create Table voucher

    (

    VoucherID int,

    LocationID int,

    SNo int,

    aaa varchar(100),

    bbb varchar(100),

    CONSTRAINT PK_Voucher PRIMARY KEY(voucherID,LocationID,SNO)

    )

    Create Table RefTable

    (

    VID int,

    LID int,

    SNo int,

    aaa varchar(100),

    bbb varchar(100),

    CONSTRAINT FK_RefTableVoucher FOREIGN KEY(VID,LID,SNo ) REFERENCES Voucher(voucherID,LocationID,SNO)

    )

    My requirement is, if i give Table name -Voucher.

    Need to get all reference tablename ,reference column.

    How can i achieve this.

  • The schema views that should contain this will be sys.columns, sys.foreign_keys and sys.foreign_key_columns. Joins are pretty simple and obvious

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thank You

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply