mysql alter修改數據庫表結構用法

1.alter操做表字段索引

(1)增長字段table

  alter table 表名 add 字段名 字段類型;class

  alter table student add name varchar(10);im

(2)修改字段tab

   alter table 表名 change 舊字段名 新字段名 字段類型;di

   alter table 表名 modify 字段名 字段類型;//修改字段類型co

   alter table student change name name varchar(20)not null default 'liming';//修改字段類型 default後邊是index

    字段默認的值ab

   alter table student change name name1 varchar(20)not null default 'liming';//修改字段名arc

(3)刪除字段

   alter table 表名 drop 字段名;

   alter table student drop name;

2.alter 索引操做

 (1)增長索引

    alter table 表名 add index 索引名 (字段名1,字段名2.....);

    alter table student add index stu_name(name);

  (2)刪除索引

     alter table 表名 drop index 索引名;

     alter table student drop index stu_name;

  (3)查看某個表的索引

     show index from 表名;

   (4)增長惟一限制條件的索引

     alter table 表名 add unique 索引名(字段名);

 3.主鍵操做

    增長主鍵:

   alter table 表名 add primary key(字段名);

   刪除主鍵:

   alter table 表名 drop primary key;(主鍵不是自動增加狀況下)

    alter table 表名 modify 字段 字段類型, drop primary key;(主鍵是自動增加狀況下)

  alter table 123 modify id int,drop primary key;

相關文章
相關標籤/搜索