更改MySQL表的表结构
重新访问MySQL,并尝试更改表的结构。我想将两行从 varchar(30) 更改为更高。
我已经用谷歌搜索了它,并尝试了看似正确的语句,但我收到了语法错误:
ALTER TABLE 'compdetails' CHANGE 'compName' varchar(60) not null;
然而,此语句给了我一个语法错误。我也尝试过在表/列名称周围没有“”,但没有任何运气。
“错误 2064 (42000):您遇到错误 在你的 SQL 语法中......”
有人能唤起我的记忆吗?
Revisiting MySQL, and trying to change the structure of the table. I want to change two rows from a varchar(30) to higher.
I have googled it, and tried what appears to be the correct statement but I'm getting a syntax error:
ALTER TABLE 'compdetails' CHANGE 'compName' varchar(60) not null;
This statement however gives me a syntax error. I have also tried without the '' around the table/column names without any luck.
"Error 2064 (42000): You have an error
in your SQL Syntax...."
Can anyone jog my memory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
就这样:
Just so:
首先,如果你想引用表名,那么你需要使用反引号而不是单引号。单引号仅用于字符串文字。
其次,当您想要重命名列时使用 CHANGE,而 MODIFY 允许您更改列定义而不重命名它。所以你应该使用:
在线 MySQL 文档 是非常好,我鼓励您在遇到语法问题时检查它。
Firstly, if you want to quote table names, then you need to use back ticks not single quotes. A single quote is only used for string literals.
Secondly, CHANGE is used when you want to rename the column, whereas MODIFY allows you to change the column definition without renaming it. So you should be using:
The online MySQL documentation is very good and I would encourage you to check it whenever you come across problems with syntax.