mysql 修改表或表結構

2021-10-08 09:39:45 字數 590 閱讀 5420

alter table old_name rename new_name; --修改表名

alter table test add column add_col_name varchar(10); --新增表列

alter table test drop column del_col_name; --刪除表列

alter table test modify col_name varchar(10) --修改表列型別

alter table test change column old_col_name new_col_name varchar(30)--修改表列名

# 可使用命令直接進行,資料已清空

alter table tablename auto_increment=1;

# 在沒有關聯外來鍵,或者關聯外來鍵的其他表的子資料已經清除,使用命令刪除資料重置id初始值

# 和 delete from tablename 區別是:delete 有事務,速度慢 truncate 沒有事務,速度快

truncate table tablename;

mysql 修改表結構

1.mysql 修改表名字 alter table t1 rename t2 2.修改列的名字 alter table stock change column stock id id int 6 3.增加列 alter table ab add column id int 3 4.減少列 alter...

MySql表結構修改

1 在表的最後追加一列 語法 alter table 表名 add 列名 列型別 列引數 例如 alter table test add name char 30 not null default tom 2 在某列後面加一列 語法 alter table 表名 add 列名 列型別 列引數 aft...

Mysql表結構修改

修改場景 建立了乙個表但是忘記把主鍵設定為自增長 create table work info work id int 11 not null,company varchar 64 default null,position varchar 32 default null,duty varchar ...