开发者

is this correct mysql syntax for alter table

Alter table users 
Add  
{ 

};

and if so how would i add all three of these columns

`user_id` varchar(16) DEFAULT NULL,
`u开发者_StackOverflow中文版ser_location` tinytext,
`author_id` varchar(16) DEFAULT NULL,


To be honest, you're not really doing yourself any favours by asking such as question, as you won't learn anything from an actual answer. (i.e.: Someone telling you the correct syntax won't help you learn.)

As such, what you should do is:

  1. Look at the ALTER TABLE syntax on MySQL.com

  2. Make a copy of the table in question. (You can use a "CREATE TABLE <new table name> LIKE <existing table name>;" to do this and populate it by using a "SELECT INTO <new table> FROM <old table>;", etc. (Here's the SELECT INTO syntax.)

  3. Try out your proposed ALTER TABLE on the copy to ensure it does what you want.

  4. If it does (of indeed if it doesn't) you can use "DROP TABLE <new table name>;" to dispose of the newly created table.

By doing this, you'll learn as you go which is a lot more valuable in the long run.


ALTER TABLE users ADD (
  `user_id` varchar(16) DEFAULT NULL,
  `user_location` tinytext,
  `author_id` varchar(16) DEFAULT NULL);


ADD [COLUMN] (col_name column_definition,...)

So can't you just separate each one of the parameters with comma.

ALTER TABLE users
ADD `user_id` varchar(16) DEFAULT NULL,
ADD `user_location` tinytext,
ADD `author_id` varchar(16) DEFAULT NULL;

Source: http://dev.mysql.com/doc/refman/5.5/en/alter-table.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜