Use SQL to see what tables keys / indexes exist on a table

Last post 07-18-2012 8:37 AM by BtrieveBill. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 07-17-2012 6:13 PM

    Use SQL to see what tables keys / indexes exist on a table

    Howdy,

    Is there any to use SQL to query the "DDF" files to see what tables exist and what keys/indexes/foreign keys exist on a given table? 

     Thanks

    dbl

  • 07-17-2012 7:55 PM In reply to

    Re: Use SQL to see what tables keys / indexes exist on a table

    You can query the system tables directly, but this is a bit tough.  A query like this will return all the index records for a given table:

    SELECT * FROM X$Index
    WHERE Xi$File IN (SELECT Xf$Id FROM X$File WHERE Xf$Name = 'tablename')

    However, this will not give you the field names.  If you want field names, you have to join in X$Field, and a second JOIN if you want index names, also.

     

    A better solution is to use the system stored procedure, psp_indexes().  A command like this will work for you:

      CALL psp_indexes(,'tablename');

     

    Finally, you can use the system catalog functions, such as dbo.fSQLForeignKeys and dbo.fSQLPrimaryKeys.

     

  • 07-17-2012 9:06 PM In reply to

    Re: Use SQL to see what tables keys / indexes exist on a table

    Thanks I'll look into those.  The two links for ForeignKeys and PrimaryKeys don't go to valid pages.

     Thanks

    dbl

  • 07-18-2012 12:00 AM In reply to

    Re: Use SQL to see what tables keys / indexes exist on a table

  • 07-18-2012 8:37 AM In reply to

    Re: Use SQL to see what tables keys / indexes exist on a table

     I was being lazy -- instead of typing the text, I did a copy & paste from the product manuals.  This attempted to copy the links over for some odd reason.  All of this information is indicated in the on-line help.

Page 1 of 1 (5 items)