mos wrote:
Chris,
You probably want to know the specific table, so I wonder if it shows up in the MySQL error logs? Of course you can dump the database structure and look for key "x" by doing:

mysqldump --no-data --skip-opt --skip-comments --compact

and redirect it out to a text file. Hopefully it only shows up in one table. I always trap my SQL errors and write them out to my own log so I know exactly what operation is failing, including the SQL that caused it. I use a compiled language so it's easy enough to trap exceptions.

I should have given a bit of context for my question. I am working on a tool for editing records. Some of the tables have a unique key for things like user name. When the tool is being used to create a new record and I get a duplicate entry error I want to capture it and present a better error to the user so he knows what to fix. In most cases it is key 2. However some tables have several keys so I need a way to find out what field(s) are part of that key so I can present a message like "The User Name you entered is already being used and must be unique, please use a different value." Like I said this tool is designed to be somewhat general. I was hoping that something like "SHOW COLUMNS FROM `TableName`", would give me the information I need. That query will tell me that UserName is a unique key, but how do I know it is Key 2 or 3 etc. I assume that the primary key is key 1 but other than that I'm not sure how I can now what the other ones are if there is more than one additional unique key.

--
Chris W
KE5GIX

"Protect your digital freedom and privacy, eliminate DRM, learn more at http://www.defectivebydesign.org/what_is_drm";

Gift Giving Made Easy
Get the gifts you want & give the gifts they want One stop wish list for any gift, from anywhere, for any occasion!
http://thewishzone.com


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

Reply via email to