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

When inserting a row, do I have to write NULL for the id to make use of the autoincrementing property?

INSERT INTO <table> VALUES(NULL, "bla", "bla");

here, the first entry is autoincrementing so I want to make use of that. Do I have to assign it the NULL value?

1 Answer

Joshua Goss
Joshua Goss
5,609 Points

Just to add that in case you don't specify the column names, then you need to enter NULL for the id column.

So while this passes ok

INSERT INTO actors (name) VALUES ("John Smith");

This doesn't

INSERT INTO actors VALUES ("John Smith");

and you would have to use NULL like this

INSERT INTO actors VALUES (NULL, "John Smith");