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:
Look at the ALTER TABLE syntax on MySQL.com
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.)Try out your proposed ALTER TABLE on the copy to ensure it does what you want.
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
精彩评论