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 trialMichael Newman
39,508 PointsWhy 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.
1 Answer
Michael Newman
39,508 PointsI 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.