简体   繁体   English

这是Alter表的正确mysql语法吗

[英]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,
`user_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. 老实说,您不会通过提问等方式给自己带来任何好处,因为您不会从实际答案中学到任何东西。 (ie: 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 查看MySQL.com上的ALTER TABLE语法

  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 .) (您可以使用“ CREATE TABLE <new table name> LIKE <existing table name>; ”来执行此操作,并使用“ SELECT INTO <new table> FROM <old table>; ”来填充它,等等。(这里是SELECT INTO语法 。)

  3. Try out your proposed ALTER TABLE on the copy to ensure it does what you want. 副本上尝试您建议的ALTER TABLE,以确保它可以满足您的要求。

  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. 如果可以(确实可以),则可以使用“ DROP TABLE <new table name>; ”来处置新创建的表。

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 资料来源: http : //dev.mysql.com/doc/refman/5.5/en/alter-table.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM