mysql簡單的修改表結構語句

2021-08-18 06:05:10 字數 1110 閱讀 3621

mysql語句

使用資料庫格式

use 資料庫名;

在表中新增新的字段:

alter table 表名 add 列名 型別 ;
注:可以在型別後新增約束條件格式如下 :

alter table 表名 add 列名 型別 unique;

在表中新增多個新的字段:

alter table 表名 add 列名 型別,add 列名 型別;

利用desc命令檢視表的字段資訊:

desc 表名;
新增已有**中新增唯一性約束:

alter table 表名 add unique(列名);
或者

create unique index 自己定義的約束名 on 表名(列名);
利用資料字典檢視表的約束資訊:

select * from information_schema.table_constraints;

刪除字段:

alter table 表名 drop 列名;
刪除多個字段:

alter table 表名 drop 列名,drop 列名;
刪除唯一性約束:

alter table 表名 drop index 約束名;
不清楚約束名可以輸入下面語句查詢約束名:

show key from 表名;
修改字段長度:

alter table 表名 motify column 列名 新型別長度;

備份資料庫

mysqldump -h 127.0.0.1 -p[埠號] 

-u root -ppassword dbname >e:\expo-today_backup\database\[檔名].sql

MYSQL修改表結構語句 alter

mysql修改表結構語句 alter create table user id int primary key auto increment,username varchar 20 unique,password varchar 20 not null,age int,birthday date 修...

MYSQL的修改表結構SQL語句

使用sql語句對錶結構進行修改 案例 表結構 create table login user id int 32 not null auto increment,name varchar 225 character set utf8 collate utf8 general ci default n...

修改表結構語句

修改表結構語句 1.修改資料表名 alter table 使用者.old table name rename to new table name 2.修改列名 alter table 使用者.table name rename column old column name to new column...