Hi Stig,

Where in that query do you define the table you are using?
  ----- Original Message ----- 
  From: Stig Manning 
  To: [email protected] 
  Sent: Wednesday, February 04, 2009 4:53 PM
  Subject: [phpug] Re: [OT] Get Primary Key column name using SQL


  Hi Aaron,

  You can perform SQL statements on the INFORMATION_SCHEMA table.

  So you can do a lookup like 

  select CONSTRAINT_SCHEMA, TABLE_NAME, COLUMN_NAME from KEY_COLUMN_USAGE where 
CONSTRAINT_NAME = 'PRIMARY';

  Or define the CONSTRAINT_SCHEMA to specify a DB.

  Cheers,
  Stig

  Aaron Cooper wrote, on 4/02/2009 2:39 PM: 
    Hi All,

    Can't find anything on this in the docs. Does anyone know of a way off the 
top of their head how you can return the name of a table's primary key using 
SQL. 

    I've figured out how to get foreign keys using the REFERENCED_COLUMN_NAME 
constant, but there doesn't appear to be any such constant for Primaries.

    Cheers
    Aaron





  

--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
-~----------~----~----~----~------~----~------~--~---

Reply via email to