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...

2 Answers

Tim Abbott
Tim Abbott
13,323 Points

Great thanks. Will do next time!

Steven Parker
Steven Parker
177,495 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
13,323 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
177,495 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.