Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Mohamed Elauzei
Mohamed Elauzei
2,191 Points

Insert Statement Challenge

Hi there

When I run this code { INSERT INTO products (id, name, description, price) VALUES (1, "jeans", "hdksjfjee nfis", 9.9); }

for the challenge it gives me an error saying that I only entered 3 values when it expects 4 entries, even though I actually did provide 4 entries.

I have no idea why this is happening.

1 Answer

Steven Parker
Steven Parker
210,936 Points

The table already has 3 entries, your code should insert a 4th. So the error message is just saying it did not work.

The clue is where the instructions say "The id column is auto incrementing." An auto-increment column should not be given an explicit value, so the "id" column can be given a "null" value, or it can be omitted entirely.

Mohamed Elauzei
Mohamed Elauzei
2,191 Points

I actually first tried omitting the "id" value because it's auto incrementing and it didn't work. But I now tried inserting a NULL value and it worked. Thanks a lot.

Steven Parker
Steven Parker
210,936 Points

This would also work:

INSERT INTO products (name, description, price) VALUES ("jeans", "hdksjfjee nfis", 9.9);

Happy coding!