0

I have created my table and modified my column so it INCREMENT BY 1

I don't understand how to actually use that auto increment in to an INSERT query,

If I try to skip it, thinking the table would automatically pick it up, it throws an error. If I try to use a value such as 0, the second time I run the query, it throws an error for repeating primary keys.

How to actually use it in an insert, so it increments on its own every time I run a query?

Emil Mladenov
  • 320
  • 1
  • 4
  • 10
  • Can you show us your create table statement and the statement you used to create the auto increment column? – Tim Biegeleisen Feb 07 '17 at 00:14
  • When you skip it, what error do you get? – Tim Biegeleisen Feb 07 '17 at 00:15
  • @TimBiegeleisen `CREATE TABLE "CAMPAIGNS" ( "campaignName" VARCHAR(200), "campaignLocation" VARCHAR(200), "campaignManager" VARCHAR(200) ); ` And then I add a custom column with the netbeans IDE, and I put INCREMENT BY 1 in the window – Emil Mladenov Feb 07 '17 at 00:18
  • Also, which database are you actually using? – Tim Biegeleisen Feb 07 '17 at 00:19
  • @TimBiegeleisen error is `[Exception, Error code 30,000, SQLState 42802] The number of values assigned is not the same as the number of specified or implied columns.` – Emil Mladenov Feb 07 '17 at 00:20
  • @TimBiegeleisen JavaDB – Emil Mladenov Feb 07 '17 at 00:21
  • I don't know this database. It sounds like your insert statement is unbalanced. – Tim Biegeleisen Feb 07 '17 at 00:22
  • 1
    The `SQLState` suggests that your database is DB2, however the tag is MySQL. If you're looking for a DB2 Solution, please see http://stackoverflow.com/q/13466347/2298301. And, if you're wanting to add an auto-increment to MySQL, then something like... `CREATE TABLE your_table ( id int unsigned NOT NULL AUTO_INCREMENT, name varchar(200), PRIMARY KEY (id) );` – Dhruv Saxena Feb 07 '17 at 02:43

0 Answers0