tags:

views:

105

answers:

4

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 [ ] mean or the { } mean or the pipes

is there some kind of tutorial that can help me understand this?

+5  A: 

[] 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

zerkms
+12  A: 
  • The brackets [ ] denote optional expressions
  • The pipes mean OR.
  • The braces { } group words for the pipes.

For example:

  • [COLUMN] means that the word COLUMN can optionally appear
  • {INDEX|KEY} means that either INDEX or KEY must appear
  • [FIRST | AFTER col_name ] means that the word FIRST or AFTER (the name of a column) can optionally appear
SLaks
do you know how this convention named? cannot google it :-(
zerkms
@zerkms: I don't think it's necessarily a standard convention; the developers of MySQL could have made it up. I don't know for sure, though.
musicfreak
it's a very close relative or derivation of EBNF http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form
rmeador
@rmeador: thanks
zerkms
+2  A: 

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).

Scorchio
+4  A: 

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.

arnorhs