Get the primary key of a database table?
Posted: Fri Apr 08, 2011 7:22 am
Hi, does anyone know how to find out which is the primary key in a database?
revDatabaseTableNames(databaseID) (excellent, gives you the table names)
revDatabaseColumnNames(recSetID) (as above, for columns)
revDatabaseColumnTypes(recSetID) (thank you rev, tells you data types, crucial 'cause the SQL queries are different for strings & integers).
But to update you need the primary key, since, at least in SQL server and MS access, trying to update the primary key row causes an error (be so much better if these databases simply ignored attempts to update un-updateable columns and continued on to do the rest of the row--but they don't).
So, is there any way for rev/livecode to query a database table and obtain the name of its primary key (if any)?
Seems the SQL for this varies between database programs and i'd like this app to work with any database (and it's essential it works with the various versions of ms access & SQL server).
Presumably this isn't an easy ask or rev would offer a command like revPrimaryKey(databaseID,table_name) but maybe i'm missing something.
Steve
revDatabaseTableNames(databaseID) (excellent, gives you the table names)
revDatabaseColumnNames(recSetID) (as above, for columns)
revDatabaseColumnTypes(recSetID) (thank you rev, tells you data types, crucial 'cause the SQL queries are different for strings & integers).
But to update you need the primary key, since, at least in SQL server and MS access, trying to update the primary key row causes an error (be so much better if these databases simply ignored attempts to update un-updateable columns and continued on to do the rest of the row--but they don't).
So, is there any way for rev/livecode to query a database table and obtain the name of its primary key (if any)?
Seems the SQL for this varies between database programs and i'd like this app to work with any database (and it's essential it works with the various versions of ms access & SQL server).
Presumably this isn't an easy ask or rev would offer a command like revPrimaryKey(databaseID,table_name) but maybe i'm missing something.
Steve