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 a Row to a Table

Michael Newman
Michael Newman
38,872 Points

Why does Andrew specify the column names on the "INSERT INTO loans" example?

I'm pretty sure I'm missing something obvious, but why does he explicitly state the column names (i.e. id, book_id, patron_id, etc.). My best guess is he is stating only the fields he wants to add, but I'm not sure why some of these are NULL.

Michael Newman
Michael Newman
38,872 Points

I spoke way too soon, should've just finished the video. For anyone else wondering like I was I'll give explaining it my best shot (please correct me if I'm wrong).

Stating the column names will tell the database which fields you are adding. You can explicitly state less fields than the total schema requires and it knows that the values you are adding below to those column fields only. If you omit a field (such as book_id like in Andrew's example) the database will know to skip over that value and go to the next value you provide.