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

We have an eCommerce database and it has a products table. It has the columns id, name, description and price...

confused...

4 Answers

Tim Abbott
Tim Abbott
14,206 Points

Great thanks. Will do next time!

INSERT INTO products (name, description, price) Value ('t-shirt','white',2.99); I don't understand what is wrong with this code

Try this: INSERT INTO products(name, description, price) VALUES("banana","The best fruit",3.99);

Steven Parker
Steven Parker
218,639 Points

The rest of task 1 says, "Add a new product to the products table. Use any valid values you want. All columns are required. The id column is auto incrementing."

Since the ID column is auto incrementing, it can be left out. So you'll want to construct an INSERT statement that names the other 3 columns, and then supply VALUES for each of them. You can make up anything, it won't care as long as you supply all 3.

Give it a shot, and if you still have trouble post your code here for further assistance.

Tim Abbott
Tim Abbott
14,206 Points

Hi Steve,

I don't see what's wrong with this?

INSERT INTO products (id, name, description, price) VALUES (NULL, Jeans, Blue, £70);

The Error Message says: Was expecting 4 entries in the products table. There's only 3. This suggests that the id with a NULL value is required? I've also tried it without the column names, thinking that may come next.

Thanks in advance....again! Tim

Steven Parker
Steven Parker
218,639 Points

Hi, Tim.

In future, please start a fresh new question to give others a chance to respond to it (plus the ability to vote on answers).

But literal string values (like 'Jeans') must be enclosed in quotes, and the "price" value should be just a number (no currency symbol). Give that a shot.