close

1.

修改欄位名稱和type

 

alter table users change last_name name varchar(10)

2.

修改type

 

alter users modify last_name text

3.

增加欄位

 

alter table users add age int(15)

4.

將 id 修改為primary key 要 auto_increment

alter table t1 modify id int primary key auto_increment

 

5.

將 id 的primary key 取消

 

5.1

要先把auto_increment 取消

alter users modify id int 

這時primary key還在

 

5.2

再drop primary key

alter users drop primary key

 

6.

修改成有default或default value

alter table users alter column id set default '5000'  <<不用打type

alter table users  modify price int default '1000'<<要打type

7.

取消default

alter table users alter column id drop default

8.

修改顯示順序

alter table uers modify id int after shit1

alter table users modify id int after first

9.

加入索引

9.1 既有欄位單索引

alter table add index(price)

create index shi_index on uers (yy)

9.2

既有欄位複合索引

alter table t1 add index index_name(yy,id)

create index cc_yy on users (yy,cc)

//ps    text類型不能 index

10.

刪索引

drop index index_name on users

alter table t1 drop index shit_id

11.增加 unique index

alter table t1 add unique( cc)

11.1 刪unique index

alter table t1 drop index index_name_unique

12.

刪欄位

alter table t1 drop column1

13.創建table時建立composite primary key(複合主鍵)

create tabe t2(name varchar(50) not null ,id int not null,contraint primary key(name,id) )

13.1刪複合主鍵

alter table t2 drop primary key

13.2 已有表,修成 複合主鍵

alter table t2 add constraint sf primary key(name,c_id)

 

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 學習程式 的頭像
    學習程式

    程式學習日記,如果我幫助了你請讓我知道

    學習程式 發表在 痞客邦 留言(0) 人氣()