Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Robbie Thomas
Robbie Thomas
31,093 Points

Inserting Data Code Challenge 2/2

Tried this:

INSERT INTO actors VALUES ("Micheal J. Fox");

And it's telling me to go screw myself. What does the code challenge want? I'm confused...

2 Answers

Robert Bojor
PLUS
Robert Bojor
Courses Plus Student 29,439 Points

Hi Robert,

When you are trying to insert into a table and not specify the actual columns before the VALUES keyword, the SQL server expects you to supply all the field values, in the same order they were created in the table.

For example, you have the table actors, which normally should have a column called id and another column called name. You can write the insert query in two different ways:

INSERT INTO actors (name) VALUES ('Michael J. Fox');

or

INSERT INTO actors VALUES (NULL, 'Michael J. Fox');

If your first column has autoincrement, it will take the first NULL and assign it the next available number and insert the name on the row.

You can always specify the next number instead of NULL but that will require you to find what that next number is first, and it is actually better to let the SQL server do that for you.

Robbie Thomas
Robbie Thomas
31,093 Points

Heh, the guy on the video didn't mention single quotation marks. Thanks.

Robert Bojor
Robert Bojor
Courses Plus Student 29,439 Points

I prefer them because I wrap my queries into double quotes, so in order not to escape them all the time, I use the single ones inside the query.

The Hacker
The Hacker
20,260 Points

Could you be more specific?

Robbie Thomas
Robbie Thomas
31,093 Points

It's under MySQL, gone that far?