PDA

View Full Version : Get primary and foreign keys from tables



NoRulez
4th November 2008, 10:16
Hey @all,

did anybody know a way to get the primary and foreign keys from a table?

so when I have a table 'A'


id integer primary key
cid integer foreign key (foreign key for table 'B' column 'id')

and table 'B'


id integer primary key


I want to know that in table 'A' a primary key 'id' exists and there is a foreign key 'cid' which is in table 'B' defined.

Regards

caduel
4th November 2008, 11:04
You can use QSqlTableModel::primaryKey() to get the primary key.
Foreign key detection is, afaic, not supported by Qt and has to be done in a database-dependant manner.

HTH

NoRulez
5th November 2008, 12:16
Ok, thanks

I had thought there are Qt ways to do this for all available Databases.

Regards