Rich,

>How can I select primary key from a table?

To retrieve PKs for db.tbl in MySQL 5 ...

SELECT k.column_name
FROM information_schema.table_constraints t
JOIN information_schema.key_column_usage k
USING(constraint_name,table_schema,table_name)
WHERE t.constraint_type='PRIMARY KEY'
 AND t.table_schema='db'
 AND t.table_name='tbl';

Pre-5, parse the result of DESC tbl or SHOW KEYS FROM tbl.

PB

Rich wrote:
Hi folks. How can I select primary key from a table? I can't find any syntax out of show fields from tablename, and the 'key' field = "PRI". Just seems to be a bit much.

Any takers?

Cheers


Rich in Toronto (cold)



--MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



--No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.411 / Virus Database: 268.17.37/682 - Release Date: 2/12/2007




--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.411 / Virus Database: 268.17.37/682 - Release Date: 2/12/2007


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to