alter 向表中增加刪除字段


 

 

  1. stu(
  2.  
    id, name,age,addr,note
  3.  
    )

在 stu表的age后面新增字段;

alter table stu add column sex char(1) null comment '性別' after age;

ALTER TABLE status ADD id VARCHAR(100) DEFAULT '' COMMENT '學生Id' AFTER room;

alter add命令用來增加表的字段。

alter add命令格式:alter table 表名 add字段 類型 其他;

例如,在表MyClass中添加了一個字段passtest,類型為int(4),默認值為0:
   mysql> alter table MyClass add passtest int(4) default '0';

1) 加索引
   mysql> alter table 表名 add index 索引名 (字段名1[,字段名2 …]);

例子: mysql> alter table employee add index emp_name (name);

2) 加主關鍵字的索引
    mysql> alter table 表名 add primary key (字段名);

例子: mysql> alter table employee add primary key(id);

3) 加唯一限制條件的索引
   mysql> alter table 表名 add unique 索引名 (字段名);

例子: mysql> alter table employee add unique emp_name2(cardnumber);

4) 刪除某個索引
   mysql> alter table 表名 drop index 索引名;

例子: mysql>alter table employee drop index emp_name;

5) 增加字段
    mysql> ALTER TABLE table_name ADD field_name field_type;

6) 修改原字段名稱及類型
    mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;

7) 刪除字段
    MySQL ALTER TABLE table_name DROP field_name;

原文鏈接:https://blog.csdn.net/u013063153/article/details/53304325

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM