ALTER table good_detail ALTER COLUMN brand NULL;
ERROR 1064 (42000): You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server
version for the right syntax to use near 'NULL' at line 1
! 不要怀疑,一定是你的语法错了,第一句报错就说了是语法错误,然后到底哪里错了,NULL前面 其实就是 ALTER COLUMN 错了
点击这里速度查手册,以下为手册的翻译:
1. CHANGE:用在同时要变列定义与列名
- Can rename a column and change its definition, or both.
// 1. 改列名与改定义都支持- Has more capability than MODIFY or RENAME COLUMN, but at the expense of convenience for some operations.
// 2. 比 MODIFY 和 RENAME COLUMN 有更多能力,但是以牺
牲一些操作的便利性为代价
// 同时变列名与定义
ALTER TABLE `tab1` CHANGE col_a col_b BIGINT NOT NULL;
- CHANGE requires naming the column twice if not renaming it, and requires respecifying the column definition if only renaming it.
// 3. CHANGE 需要使用命名列2次如果不是要重命名,就算只是改名,也需要重新声明列的定义
// 只变定义,需要写2次列名
ALTER TABLE `tab1` CHANGE col_b col_b INT NOT NULL;
- With FIRST or AFTER, can reorder columns.
// 4. 用 FIRST 或 AFTER 可以变换列顺序
2. MODIFY:用在改变列定义
- Can change a column definition but not its name.
// 1. 只能改定义不能改名字- More convenient than CHANGE to change a column definition without renaming it.
// 2. 比 CHANGE 更方便的改变列,不需要改名
// 2的示例
ALTER TABLE tab_1 MODIFY col_b INT NOT NULL;
// 只改属性,change only INT to BIGINT 但是这样会让其他属性消失
ALTER TABLE t1 MODIFY col1 BIGINT;
// 完整的改法还是要把其他定义带上
ALTER TABLE t1 MODIFY col1 BIGINT UNSIGNED DEFAULT 1
COMMENT 'my column';
- With FIRST or AFTER, can reorder columns.
3. RENAME COLUMN:只能改列名
- Can change a column name but not its definition.
1. 能变列名而不是定义- More convenient than CHANGE to rename a column without changing its definition.
2. 更方便的rename不需要重复定义语句
// 只变名字
ALTER TABLE t1 RENAME COLUMN b TO a;
// 错误的示范 -- swap a and b
ALTER TABLE t1 RENAME COLUMN a TO b,
RENAME COLUMN b TO a;
// 正确的示范 -- "rotate" a, b, c through a cycle
ALTER TABLE t1 RENAME COLUMN a TO b,
RENAME COLUMN b TO c,
RENAME COLUMN c TO a;
4. ALTER:只能改某列的默认值
- Used only to change a column default value.
// 只能用来变换值
总结:
change的话,表示变化很大,所以定义和名字可以修改
modify,改变一部分,就是定义
rename,字面意思,列名
alt,改变列默认值
联想下英文本身的意思也是这样啊,最后其实一张图解决了记忆问题
如何记忆change, modify, rename, alt
这次就到这里
网友评论