Page 1 of 1

looking for primary key field

Posted: Fri 14 Dec 2007 16:27
by Willo
Hi;

does any one knows if tere is a way to know which field is the primary key in a table?

i have a rutine that logs changes on a table at field level, but i need to log the record's primary key as well.



TIA

Posted: Mon 17 Dec 2007 08:49
by Antaeus
You can use the DESCRIBE table_name command to get such information about a table.

You can determine key fields in a dataset by MyDAC means in the following way:

Code: Select all

var
  i: integer;
begin
  MyQuery1.Open;
  for i := 0 to MyQuery1.FieldCount - 1 do
    if MyQuery1.GetFieldDesc(MyQuery1.Fields[i].FieldName).IsKey then
      ShowMessage(MyQuery1.Fields[i].FieldName + ' is in key');