|
-
July 15th, 1999, 06:35 AM
#1
Primary Key
How can I set up a primary key in ADO connection to create table ? Thanks
-
July 15th, 1999, 07:09 AM
#2
Re: Primary Key
here you have an example of how to make a new table, it also includes a primary key
Sub NewTable()
Dim dbs as Database
Dim tdf as TableDef, fld1 as Field, fld2 as Field
Dim idx as Index, fldIndex as Field
' Return reference to current database.
set dbs = CurrentDb
' Create new table with two fields.
set tdf = dbs.CreateTableDef("Contacts")
set fld1 = tdf.CreateField("ContactID", dbLong)
fld1.Attributes = fld1.Attributes + dbAutoIncrField
set fld2 = tdf.CreateField("ContactName", dbText, 50)
' Append fields.
tdf.Fields.Append fld1
tdf.Fields.Append fld2
' Create primary key index.
set idx = tdf.CreateIndex("PrimaryKey")
set fldIndex = idx.CreateField("ContactID", dbLong)
' Append index fields.
idx.Fields.Append fldIndex
' set Primary property.
idx.Primary = true
' Append index.
tdf.Indexes.Append idx
' Append TableDef object.
dbs.TableDefs.Append tdf
dbs.TableDefs.Refresh
set dbs = nothing
End Sub
-
July 15th, 1999, 07:09 AM
#3
Re: Primary Key
conn.execute "create table x( col1 varchar(10) primary key)"
at least this works for SQLServer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|