My Assistant
![]() ![]() |
|
|
Mar 19 2004, 10:46 AM
Post
#1
|
|
|
UtterAccess Enthusiast Posts: 51 From: New York |
Is there any way to create an auto number field using SQL?
What I'm doing: I've created a query which creates a table I want the table to have a field that has a unique ID (auto number field) that every time the query gets preformed gets refreshed hence creating an auto number field in SQL in the original query... Hope this makes since and hope someone can help... Thanks! Lydia |
|
|
|
Mar 19 2004, 10:58 AM
Post
#2
|
|
|
UA Editor + Utterly Certified Posts: 22,726 From: Melton Mowbray,Leicestershire (U.K) |
Hi
Here is some SQL that creates a table with an autonumber and a couple of fields, you could run this first then append your records after.. CODE Sub sCreate1() Dim db As Database Dim strSQL As String Set db = DBEngine(0)(0) strSQL = "CREATE TABLE [Table1New] (FieldPK COUNTER CONSTRAINT PrimaryKey PRIMARY KEY, FieldOne TEXT, FieldTwo TEXT );" db.Execute strSQL Set db = Nothing End Sub HTH's (IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif) |
|
|
|
Mar 19 2004, 12:19 PM
Post
#3
|
|
|
UtterAccess Addict Posts: 123 From: Glendale, CA |
Or you could do it the other way around.
this sql code should add an autonumber field that is the primary key to an exisiting table: ALTER TABLE temp ADD COLUMN id COUNTER CONSTRAINT pkey PRIMARY KEY |
|
|
|
Mar 19 2004, 01:35 PM
Post
#4
|
|
|
UtterAccess Enthusiast Posts: 51 From: New York |
Great thanks!
It works Great! Lydia |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 20th June 2013 - 01:37 AM |