Web Hosting Talk







View Full Version : MySQL: Primary Keys in Views via Describe


vibrokatana
08-28-2008, 04:40 PM
Ok, I am working with a really stupid application. In order for certain functions to work properly it needs to be able to see a primary key. The problem is we are working with a relational database and use a view to fetch the data. When the program scans the table (using describe or a similar query) it looks for the "PRI" in the key column, which is of course missing from the view.

The other option is to periodically download a rather ugly XML schema mapping it generates and manually add in the elements and key fields. However this is rather ugly and I am not even sure it will take it (it places the views in a separate definition, so it would be rather extensive, the file has over 1800 lines). And this would have to be updated every time the views are modified (usually about once every 5-8 months).

The "perfect" solution would be to define the primary key attribute for the views. However I don't think this is possible with MySQL, as the view syntax does not mention it.

TheSimpleHost-Nathan
08-28-2008, 08:25 PM
I don't really understand what you're trying to say. From all i see is that you don't think you can create Primary Keys with MySQL.

Care to explain a little better?

foobic
08-28-2008, 09:06 PM
It seems to me that the problem is already clearly explained. IDK the answer though. ;)

As I understand it views don't have indexes, they just use the indexes on the underlying tables. So... change your program or don't use views?

For more expert answers you might try asking the question on the MySQL forums (http://forums.mysql.com/list.php?100).

vibrokatana
08-28-2008, 09:16 PM
As I understand it views don't have indexes, they just use the indexes on the underlying tables. So... change your program or don't use views?

The views execute in under .05s, so they are well indexed :P

The problem is the god forsaken application wants to see a primary key. Since it doesn't see a primary key it goes on the fritz as it doesn't know how to uniquely identify the data.

And I am sure the users will utterly enjoy decoding integers to random tidbits of data. Oh yes, that object has a objtypeid of 5, what was that again?

I am about ready to strangle the major designers of this application. I think we have hit more bugs then things that work. And it only gets worst as time goes on...