Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make Table / Making a ID Field

Status
Not open for further replies.

Shadez

Programmer
Jul 5, 2001
57
US
Is there a way to designate a the ID field through the sql statement as you create the table? I am currently working on an import utility I have included the sql statement from a small table.

Any help would be great.

SELECT dbo_States.StateID, dbo_States.StateAbbr, dbo_States.StateName INTO States
FROM dbo_States;


 
You can't do it through the SQL, but you can add the field just after, and you could do it programmatically, using DAO it's get the TableDef, then the CreateField method (you can pull both of those up in VBA Help).

The other solution, if your SQL is staying pretty much the same, is to define the table as you want it, then run first a delete, then an append query against the table. Allows not only for an AutoNumber field, but also for things like primary-key control. Personally I almost never use make-table queries...
 
You can add an index field with an sql statement.
docmd.runsql "alter table add column field counter constraint primary key"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top