RE: How can I tell if a field in a table is a primary field or not
- From: MrSmersh <MrSmersh@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 25 May 2006 04:41:01 -0700
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
- Prev by Date: Re: DB_SEC_E_AUTH_FAILED: Cannot insert data into table
- Next by Date: Runtime-error '-2147024882(8007000e)' Not enough storage available to complete this operation.
- Previous by thread: Re: DB_SEC_E_AUTH_FAILED: Cannot insert data into table
- Next by thread: Runtime-error '-2147024882(8007000e)' Not enough storage available to complete this operation.
- Index(es):
Relevant Pages
|
|