Getting Key & Default Values

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Posts: 1
Joined: Tue 18 May 2010 19:04

Getting Key & Default Values

Post by xanatek » Tue 18 May 2010 19:08

I was wondering if there was a way to get the unique/primary/foreign keys via SDAC components. I would like to be able to know what field contains one of these.

Also, is there a way to retrieve the default value for a field?

Devart Team
Posts: 2885
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 19 May 2010 08:11

You can learn if the field is key using the TFieldDesc.IsKey property. To get the TOLEDBFieldDesc object of the field you should use the following code:

Code: Select all

  MSQuery.GetFieldDesc('FieldName') as TOLEDBFieldDesc
In order to know the default value of a field you should set the TMSQuery.Options.DefaultValues property to True before opening a dataset and after opening it you can use the TFields.DefaultExpression property that holds the default value.

Also you can use the TMSMetadata component to obtain metainformation about database objects from the server, including information about primary key.

Post Reply