> In the last episode (Jan 11), Steffan A. Cline said: >> Is there anyway to do a SELECT or DESCRIBE or SHOW statement which can >> return the primary key field of a specified table? >> >> Pseudo code: select primary_key_field_name from mytable. > > SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE > WHERE TABLE_SCHEMA='myschema' AND TABLE_NAME='mytable' > AND CONSTRAINT_NAME='PRIMARY' > ORDER BY ORDINAL_POSITION; > > For multi-column indexes, you will get multiple rows back. > > You should also use "show create table mytable" or "show keys from > mytable" but you'll have to do extra parsing.
Dan, Great! This is what I was after... I am building a class/ctype for Lasso for a user db. When it is instantiated, it loads the structure into the type from the db. Now, I have the primary key as the ID of the type I need to separate it from the rest of the columns. SO, I guess now I'll work on unless you have it handy where I can return all columns EXCEPT the primary key. Thanks Steffan --------------------------------------------------------------- T E L 6 0 2 . 5 7 9 . 4 2 3 0 | F A X 6 0 2 . 9 7 1 . 1 6 9 4 Steffan A. Cline [EMAIL PROTECTED] Phoenix, Az http://www.ExecuChoice.net USA AIM : SteffanC ICQ : 57234309 Lasso Partner Alliance Member --------------------------------------------------------------- > From: Dan Nelson <[EMAIL PROTECTED]> > Date: Fri, 12 Jan 2007 01:00:03 -0600 > To: "Steffan A. Cline" <[EMAIL PROTECTED]> > Cc: <mysql@lists.mysql.com> > Subject: Re: Primary key > > In the last episode (Jan 11), Steffan A. Cline said: >> Is there anyway to do a SELECT or DESCRIBE or SHOW statement which can >> return the primary key field of a specified table? >> >> Pseudo code: select primary_key_field_name from mytable. > > SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE > WHERE TABLE_SCHEMA='myschema' AND TABLE_NAME='mytable' > AND CONSTRAINT_NAME='PRIMARY' > ORDER BY ORDINAL_POSITION; > > For multi-column indexes, you will get multiple rows back. > > You should also use "show create table mytable" or "show keys from > mytable" but you'll have to do extra parsing. > > -- > Dan Nelson > [EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]