The table includes auto-increment. It is necessary to insert data into the table, but I do not know the number of fields to insert. I made a temporary table with all the required fields. How to make an insert without trying to insert an id which is on the autoincrement? Accordingly, the option Insert into table1 Select * from # table2

NOT SUITABLE.

  • if, having on hand all the data, you do not know which fields to insert, then it may be worth doing something else? - Sergey

1 answer 1

Make sure that the Id field is declared as int not null identity primary key Next, you can add a value to the table by explicitly specifying which fields I’ll add insert into Goods(Name, Price) - the product will be added (1, 'Морковь', 100) or without indication of explicit fields insert into Goods values ('Морковь', 100) . The same row will be entered in the table.

  • primary key - not necessarily, I took from my request, because I am working further with the product ID in other tables through a join. - Kryshtop
  • I cannot clearly indicate which fields I will add, because I do not know how many fields I will have, that’s the problem. - Timofey Bulankin
  • I made a temporary sign in which I hammered in the required fields, as it is possible to calculate these fields and enter already, xs ... - Timofey Bulankin
  • I'm afraid, not knowing which fields to add, it is unlikely that the insert query will be executed. - Kryshtop
  • Count the number of rows in the table - the aggregate function Count. - Kryshtop