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.
James Corr2,678 Points
Can someone explain how to read the syntax reference manual?
I'm working through the database foundations course but I don't quite understand how to use the MySQL Reference Manual. Or maybe I just need an explanation of the hierarchy of the manual.
The reference manual I'm referring to is seen here with the ALTER TABLE command: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html
For example how would I add a column and make it the first column in the table. I know FIRST goes in the syntax but I wouldn't be able to understand where without the video telling me where.
Ken AlgerTreehouse Teacher
SQL commands can be a challenge at first and sometimes the documentation is indeed confusing, but with some practice I am sure it will come easy.
With regards to your specific question as to how to add your column.
USE database_name; ALTER TABLE table_name ADD COLUMN column_name INTEGER FIRST;
This will add a Column named column_name of type INTEGER as the first column to the table table_name, in the database database_name.
If you set up a practice database in MySQL and use the admin tools to try some various commands out based on the documentation it can be extremely helpful for the learning process.
Hope it helps.
If you add a column without specifying a position it will be placed last, by default. If you want the column to be placed first in the table you would simply write:
ALTER TABLE categories ADD COLUMN another_column VARCHAR(100) FIRST;
ALTER TABLE [IGNORE] tbl_name ADD [COLUMN] col_name col_definition FIRST;
Basically everything is in the order you would write it. The items in square brackets  are optional and the items in bold are mandatory.
Also, the version of MySQL may change the syntax. I'm using 5.5.37 for debian-linux-gnu and using parenthesis around the column definition wouldn't work.