0

How to combine Select Into and Alter Table (ms access sql):

SELECT table1.field1
INTO table2
FROM table1;

And second one:

ALTER TABLE table2 ADD COLUMN ID autoincrement;

I was trying UNION ALL but I got message 'action query can't be used as row source'. Is it possible to combine them using different syntax?

Gloom
  • 39
  • 1
  • 11
  • No, that is not possible. – trincot Jul 17 '16 at 10:17
  • Can I use different syntax to generate new table based on existing one and add one column with auto-increment ID fields in one statement? – Gloom Jul 17 '16 at 10:20
  • You could create a macro and add the different SQLs as RunSQL actions. – trincot Jul 17 '16 at 10:55
  • You are better off first creating the table, then inserting the data. – marlan Jul 17 '16 at 10:59
  • Yes, but I tried to find the way to run them as one. Anyway thank you for answers. – Gloom Jul 17 '16 at 11:14
  • [here](http://stackoverflow.com/questions/7894673/counter-field-in-ms-access-how-to-generate) is a function for counting records in a query, you can add it as a field to the `Insert... Into` query. Real auto increment is created on an empty table – marlan Jul 17 '16 at 11:19

1 Answers1

1

You can't mix Data Manipulation Language (DML) with Data Definition Language (DDL).

You'll need to execute both statements separately, or to create a stored procedure which contains both commands.

Rubens Farias
  • 57,174
  • 8
  • 131
  • 162