发布于 3年前

MySQL修改表一次添加多个列(字段)和索引 Mysql多列删除

MySQL修改表一次添加多个列(字段)

ALTER TABLE table_name ADD func varchar(50), ADD gene varchar(50), ADD genedetail varchar(50);

MySQL修改表一次添加多个索引

LTER TABLE table_name ADD INDEX idx1 ( func), ADD INDEX idx2 ( func,gene), ADD INDEX idx3( genedetail);


删除一列时:

alter table Table Name drop [column] 列名;

删除多列时:

alter table Table Name drop column 列名1, drop column 列名2 ;

一列时,column可有可无;多列必须要有。


# 增加字段

sql= "alter table qishu_details ADD TXT_brief VARCHAR(10240) DEFAULT '0' after TXT_urls, ADD TXT_cover VARCHAR(200) default '0' NOT NULL after TXT_urls;"

cursor.execute(sql)

##删除字段 一列时,column可有可无;多列必须要有。

# sql = "ALTER TABLE qishu_details DROP column TXT_cover,DROP column TXT_brief;"

# cursor.execute(sql)

#修改字段

# sql = "ALTER TABLE 创建好的表名称 MODIFY COLUMN 创建好的表需要修改的字段INT AUTO_INCREMENT"

# cursor.execute(sql)


mysql在指定的一个字段后面添加一个字段

举个栗子:alter table inquiry add error_code varchar(3) after add_time;

说明:alter table + 表名 + add + 要添加的字段 字段类型 + after + 要跟随的字段名

alter table t_adviser_info add hold int COMMENT '0持有,1未持有' after stockname

alter table t_adviser_info add profit int comment "0盈利,1亏损" after hold

alter table t_adviser_info add weight int comment "0轻仓,1重仓" after profit

注意 Int,comment,和after 的位置

©2020 edoou.com   京ICP备16001874号-3