learning to make sense of the syntax of syntax
i want to use alter table
but the syntax posted here:
http://dev.mysql.com/doc/refman/5.1/en/alter-table.html
is very confusing
i do not understand what the 开发者_JS百科[ ]
mean or the { }
mean or the pipes
is there some kind of tutorial that can help me understand this?
- The brackets
[ ]
denote optional expressions - The pipes mean OR.
- The braces
{ }
group words for the pipes.
For example:
[COLUMN]
means that the wordCOLUMN
can optionally appear{INDEX|KEY}
means that eitherINDEX
orKEY
must appear[FIRST | AFTER col_name ]
means that the wordFIRST
orAFTER (the name of a column)
can optionally appear
[]
means, that argument inside is optional
{a|b}
means that you have to choose whether a
or b
UPD: specifically for mysql you should look over here: http://dev.mysql.com/doc/refman/5.1/en/manual-conventions.html
Example of an alter table statement to add a column to a table:
ALTER TABLE tablename ADD COLUMN columnname INT
changing a column's name:
ALTER TABLE tablename CHANGE COLUMN columnname newname INT
rename table:
ALTER TABLE tablename RENAME newname
drop a field from a table
ALTER TABLE tablename DROP columname
On the syntax side, the user @SLaks has a good answer.
Oh well. It's the full reference and I think for starting it's really an overkill. Maybe you should try more simple and informal guides on the topic, like http://www.w3schools.com/sql/sql_alter.asp or http://infogoal.com/sql/sql-alter-table.htm etc. etc. If you get a book covering basic SQL stuff I'm quite sure that you'll find a nice explanation, too. If you understand the basics, you can go with the more complicated stuff in the reference (if you need it).
精彩评论