MYSQL修改表結構語句 alter

2021-08-02 18:58:21 字數 1311 閱讀 9840

mysql修改表結構語句   alter

create table user(

id int primary key auto_increment,

username varchar(20) unique,

password varchar(20) not null,

age int,

birthday date

);/*

修改表結構語句

一共六句,好好學對後面的,多表有很大幫助.

修改表結構關鍵字,alter

*//*

1,新增列

alter table 表名 add 列名 型別(長度) 約束;

*/alter table user  add img varchar(20)

/*2,修改列型別,長度和約束

alter table 表名 modify 列名 型別約束

*/alter table user modify img int not null;

/*3,修改列名稱

alter table 表名 change 舊表名 新錶名 資料型別 約束

*/alter table user change img image int

/*4,刪除列

alter table 表名

drop

列名;

*/

alter table user drop img

/*5,修改表名

rename table 表名

to新的表名

;

*/

rename table user to users

/*6,修改表的字符集

alter table 表名

character set

字符集;

*/

alter table user  character set int;

修改表結構語句

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

mysql簡單的修改表結構語句

mysql語句 使用資料庫格式 use 資料庫名 在表中新增新的字段 alter table 表名 add 列名 型別 注 可以在型別後新增約束條件格式如下 alter table 表名 add 列名 型別 unique 在表中新增多個新的字段 alter table 表名 add 列名 型別,ad...

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...