user3296793
user3296793

Reputation: 270

SQL Insert with AUTO INCREMENT

I am trying to insert 50 values into a DB, the table has two column names, one is an ID column set to auto increment and the other is for a code.

When I attempt to do the insert I get a error.

This is my SQL code:

 INSERT INTO Names (Id, Code) 
 VALUES (NULL, 'CodeHere', NULL, 'CodeHere', NULL, 'CodeHERE' );

Upvotes: 0

Views: 246

Answers (3)

M Danish
M Danish

Reputation: 478

 INSERT INTO Names VALUES ('CodeHere'),('2CodeHere'),('3CodeHere'),('4CodeHere')

just ignore auto increment column.

Upvotes: 2

Sathiraumesh
Sathiraumesh

Reputation: 6117

Use this

 INSERT INTO Names (Id, Code) 
     VALUES (NULL, 'CodeHere'), (NULL, 'CodeHere') ,( NULL, 'CodeHERE' );

Upvotes: 2

Joakim Danielson
Joakim Danielson

Reputation: 52043

Don't include the ID column if it is auto increment and split the input to one one value per time

INSERT INTO Names (Code) 
VALUES ('CodeHere'),('CodeHere'),('CodeHERE' );

Upvotes: 3

Related Questions