RE: How can I tell if a field in a table is a primary field or not



For Access I do not have.
U can give you the SQL queries for getting the primary keys for SQL Server,
Oracle , DB2s and Postgre.

If you have problems creating the VB code for the queries I will try to do it.


"Mark" wrote:

Do you have a way (Code samples) of doing this using ADO from inside VB6? I
using an MS-Access database to test the routines.
--
Mark


"MrSmersh" wrote:

You need to find information about constraints. Primary keys are constraints.
OleDB to my knowledge does not provide them (for any database).
You theoretically have in the INFORMATION SCHEMA views this information
(INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE,INFORMATION_SCHEMA.TABLE_CONSTRAINTS).
When I did it I’ve gone to the catalog tables of each database since the
INFORMATION SCHEMA was a bit different or not filled on the some of the
databases.


"Mark" wrote:

I’m developing an application that will allow the user to connect to any
database using OLE DB.

After the user connects to the database the application provides a list of
tables for the selected database. After selecting a table, the user will get
a list of the fields contained in that table. The field list shows the field
name and its data type. Here is the code that shows the field names and data
types.

Private Sub List_Fields_In_Table(cnnDB As ADODB.Connection, strTable As
String)

Dim fld As ADODB.Field

Set rstSchema = New ADODB.Recordset
strSQL = "SELECT " & strTable & ".* FROM " & strTable & ";"
rstSchema.Open strTable, cnnDB, , , adCmdTable
' Enumerate the Fields collection of the strtable
For Each fld In rstSchema.Fields
Debug.Print "Field Name: " & fld.Name & "Data Type: " & fld.Type
Next fld

End Sub

My problem is: Why isn’t there a property or method telling me if the field
is a primary or secondary key?

Example: Debug.Print “Field Name: “ & fld.Name & “Primary Key: “ &
fld.PrimaryKey
Field Name: lngCustomerID Primary Key: True
Field Name: lngRelationShipID Primary Key: False

Thank you,
--
Mark
.



Relevant Pages

  • Re: problem using identity column as primary key
    ... >> I am thinking of creating an identity column to use it as primary key ... More and more programmers who have absolutely no database training are ... the gap in the sequence is not filled in and the sequence ... vin CHARNOT NULL REFERENCES Motorpool); ...
    (microsoft.public.sqlserver.programming)
  • Re: Updating the SQL key value
    ... before creating the database, by the time I've come to pick a primary key, ... articles, each of which must be issued under a particular licence (e.g. ... GPL GNU General Public Licence http://www.gnu ... ...
    (comp.lang.php)
  • Re: Concatenate and Null Values -- Features
    ... Tony Toews dislikes cascade deletes as well as cascade updates, ... fence regarding the use of natural versus surrogate (autonumber) keys. ... Database Normalization Tips ... For optimal database design and performance, the primary key of a table ...
    (microsoft.public.access.reports)
  • Re: simple database
    ... Into what component of the database did you enter over 100 ... The company's Employee ... ID number can be a primary key in that table, ... Possessors, and Transfers are the names he is using. ...
    (microsoft.public.access.gettingstarted)
  • Re: AutoNumber Question
    ... I would like to point out that a primary key does not need to be meaningless ... database, as it would be if it was part of relationships. ... VIN is being reused. ... so a VIN has meaning separate from ...
    (microsoft.public.access.tablesdbdesign)