UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Autonumber field using SQL    
 
   
cottonl
post 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
Go to the top of the page
 
+
Larry Larsen
post 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)
Go to the top of the page
 
+
ChrisP
post 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
Go to the top of the page
 
+
cottonl
post Mar 19 2004, 01:35 PM
Post #4

UtterAccess Enthusiast
Posts: 51
From: New York



Great thanks!

It works Great!

Lydia
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 20th June 2013 - 01:37 AM