mysql表基本操作

2021-10-24 07:47:16 字數 1449 閱讀 9555

alter table empleey drop name2

alter table empleey add name2 varchar(100)

alter table empleey modify column name varchar(2000)

alter table empleey change name name1 varchar(10)

alter table empleey comment '員工表'

alter table empleey alter column name1 set default '0'

alter table empleey modify column name1 varchar(100) comment '姓名'

mysql增加字段,修改字段,增加索引等語句

mysql語句:

1、修改表名:

rename table 舊表名 to 新錶名;

2、修改字段型別:

alter table 表名 modify column 欄位名 字段型別(長度)

3、修改欄位名稱和型別:

alter table 表名 change 現有欄位名稱  修改後欄位名稱 資料型別

4、增加字段:

alter table 表名 add 欄位名 字段型別(長度)

//批量增加字段

alter table 表名 add (欄位名1 字段型別(長度),欄位名2 字段型別(長度),...)

5、刪除字段:

alter table 表名 drop column 欄位名

//批量刪除字段

alter table 表名 drop column 欄位名1,drop column 欄位名2

6、修改字段預設值:

alter table 表名 alter column 字段 set default  預設值

7、新增字段備註:

alter table 表名 add 欄位名 字段型別(長度)default null comment '備註'

// 為表新增注釋

alter table 表名 comment '注釋'; 

索引: 

1.普通索引   新增index alter table `表名` add index 索引名 ( `欄位名` ) 

2.主鍵索引   新增primary key alter table `表名` add primary key ( `欄位名` ) 

3.唯一索引    新增unique alter table `表名` add unique ( `欄位名` ) 

4.全文索引    新增fulltext alter table `表名` add fulltext( `欄位名`) 

5.如何新增多列索引 alter table `表名` add index 索引名 ( `欄位名`, `欄位名`, `欄位名` )

Mysql表操作 基本操作

create table t5 id int,name varchar 10 show create table t5 create table t8 id int not null,name varchar 10 engine myisam default charset utf8 drop ta...

mysql基本操作 MySQL基本操作

mysql中新增使用者,新建資料庫,使用者授權,刪除使用者,修改密碼 注意每行後邊都跟個 表示乙個命令語句結束 1.新建使用者 1.1 登入mysql mysql u root p 密碼 1.2 建立使用者 mysql insert into mysql.user host,user,passwor...

mysql 基本操作 mysql基本操作

mysql 建立表,並設定主鍵自增 create table log logid int 4 primary key not null auto increment,logtitle varchar 32 not null logcontent varchar 160 not null logtim...