Databases Modifying Data with SQL Adding Data to a Database Adding Data With SQL

Gia Hoang Nguyen
Gia Hoang Nguyen
4,117 Points

Cant write the correct query. Need help

It keeps giving error "Was expecting 4 entries in the products table. There's only 3.

Please help

Thanks

KRIS NIKOLAISEN
KRIS NIKOLAISEN
Pro Student 51,836 Points

Are you using the following syntax:

INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...);

4 Answers

I assume you're referring to task 1 of the challenge? Here's one option:

INSERT INTO products (name, description, price) VALUES ('coffee', 'dark roast', 10);

After naming the table 'products', I listed the column names that I wished to add values for, then the values themselves.. It says that they database is set to auto increment, so you don't need to supply the ID number. The challenge is looking for 4 new values (id, name, description, price). The following code doesn't work:

INSERT INTO products VALUES ('coffee', 'dark roast', 10);

The previous code is trying to add 'coffee' to the ID column of the table. The ID column is set to integer, meaning it can only accept numbers, not text. Since the database is set to auto-increment, I specified which columns I wanted to add values for and the ID updated automatically.

Joni Whitworth
Joni Whitworth
1,425 Points

Mine is not working either. Can anyone help? I have:

INSERT INTO products (id, name, description, price) VALUES ("2", "Raven", "shirt", "$20");

Joni Whitworth
Joni Whitworth
1,425 Points

I am also getting the same error: "Was expecting 4 entries in the products table. There's only 3."

KRIS NIKOLAISEN
KRIS NIKOLAISEN
Pro Student 51,836 Points

When specifying columns by name you don't need to include the auto-incrementing primary key. Try this:

INSERT INTO products (name, description, price) VALUES ("Raven", "shirt", "$20");

Joni Whitworth
Joni Whitworth
1,425 Points

Oh, that worked. Thank you!