0

I'm trying to insert a new row into a database which has four fields, the first is a primary key set as auto incrementing (integer) and the other three are strings.

I insert a new with the following statement:

INSERT INTO Manufacturer VALUES ('Test1','Test2','01332232321')

But I am given the following exception:

"SQLite error\r\ntable Manufacturer has 4 columns but 3 values were supplied"

I assumed that the primary key field can be omitted as the database would automatically assign and increment the value for me.

How would I go about fixing this? Is this a simple syntatical error or do I need to rethink my approach completely?

2 Answers 2

1

You have to specify columns:

INSERT INTO Manufacturer (col2, col3, col4) VALUES ('Test1','Test2','01332232321')

or pass the NULL value for primary key column.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I never realised you had to specify the columns. I was working from sqlcommands.net/sql+insert and apparently missed the obvious part: "You are allowed to omit the list of column names in the SQL INSERT INTO clause, if you enter values for each of the table columns."
0

I think you're looking for how to AUTOINCREMENT in sqllite

also How do I create an AUTOINCREMENT field

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.