日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Mysql中用SQL增加、删除字段,修改字段名、字段类型、注释,调整字段顺序总结...

發(fā)布時間:2023/12/13 数据库 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Mysql中用SQL增加、删除字段,修改字段名、字段类型、注释,调整字段顺序总结... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

轉(zhuǎn)自:http://www.111cn.net/database/mysql/71648.htm

1.增加一個字段

?代碼如下復(fù)制代碼
//增加一個字段,默認(rèn)為空
alter table user add COLUMN new1 VARCHAR(20) DEFAULT NULL;
//增加一個字段,默認(rèn)不能為空
alter table user add COLUMN new2 VARCHAR(20) NOT NULL;



2.批量怎加字段

方法一
這里可以使用事務(wù)

?代碼如下復(fù)制代碼

bagin;?????????????????????????????????????????? //事務(wù)開始
alter table em_day_data add f_day_house7 int(11);
alter table em_day_data add f_day_house8 int(11);
alter table em_day_data add f_day_house9 int(11);
alter table em_day_data add f_day_house10 int(11);
commit;???????????????????????????????????????????? //提交事務(wù),事務(wù)結(jié)束



事務(wù)(transaction)是由一系列操作序列構(gòu)成的程序執(zhí)行單元,這些操作要么都做,要么都不做,是一個不可分割的工作單位。

方法二
mysql 批量為表添加多個字段
alter table 表名 add (字段1 類型(長度),字段2 類型(長度),字段3 類型(長度));

?代碼如下復(fù)制代碼
alter table em_day_data add (f_day_house11 int(11),f_day_house12 int(11),f_day_house13 int(11));



?
3.刪除一個字段

?代碼如下復(fù)制代碼
//刪除一個字段
alter table user DROP COLUMN new2;


?
4.修改一個字段

?代碼如下復(fù)制代碼
//修改一個字段的類型
alter table user MODIFY new1 VARCHAR(10);
//修改一個字段的名稱,此時一定要重新指定該字段的類型
alter table user CHANGE new1 new4 int;



5.批量修改字段名稱

?代碼如下復(fù)制代碼
alter table 表 change 修改前字段名? 修改后字段名稱 int(11) not null,
change 修改前字段名? 修改后字段名稱 int(11) not null,
change 修改前字段名? 修改后字段名稱 int(11) not null,
change 修改前字段名? 修改后字段名稱 int(11) not null,
change 修改前字段名? 修改后字段名稱 int(11) not null



例子:

?代碼如下復(fù)制代碼

alter table em_day_data change f_day_house11 f_day_hour11 int(11) not null,
change f_day_house12 f_day_hour12 int(11) not null,
change f_day_house13 f_day_hour13 int(11) not null,
change f_day_house14 f_day_hour14 int(11) not null,
change f_day_house15 f_day_hour15 int(11) not null,
change f_day_house16 f_day_hour16 int(11) not null,
change f_day_house17 f_day_hour17 int(11) not null



6,添加注釋

?代碼如下復(fù)制代碼
// 可以為表添加注釋
ALTER TABLE `table_name` COMMENT'注釋';
// 為字段添加注釋,同樣適用于修改
ALTER TABLE `table_name` CHANGE `column_name` `column_name` type(longth) UNSIGNED NULL DEFAULT NULL COMMENT '注釋'


7,調(diào)整字段順序:

alter table 表名
change 字段名 新字段名 字段類型 默認(rèn)值 after 字段名(跳到哪個字段之后)
例子:

?

?代碼如下復(fù)制代碼
alter table appstore_souapp_app_androidmarket;
change getPriceCurrency getPriceCurrency varchar(50)?? default null AFTER getPrice;


轉(zhuǎn)載于:https://www.cnblogs.com/hanlong/p/5711359.html

總結(jié)

以上是生活随笔為你收集整理的Mysql中用SQL增加、删除字段,修改字段名、字段类型、注释,调整字段顺序总结...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。