MySQL ALTER語法的運用方法

2022-09-28 21:36:29 字數 1900 閱讀 7571

以下的文章主要介紹的是mysql alter語法的實際運用,我們大家都知道mysql alter語法在實際應用中的比例還是很大的,所以了解一下mysql alter語法的實際運用可以很好的選擇。

mysql alte程式設計客棧r語法中alter程式設計客棧 [ignore] table tbl_name alter_spec [, alter_spec ...]

複製** **如下:

alter_s程式設計客棧pecification:

add [column] create_definition [first | after column_name ]

or add index [index_name] (index_col_name,...)

or add primary key (index_col_name,...)

or add uniquewww.cppcns.com [index_name] (index_col_name,...)

or alter [column] col_name

or change [column] old_col_name create_definition

or modify [column] create_definition

or drop [column] col_name

or drop primary key

or drop index in

or rename [as] new_tbl_name

or table_options

eg:

mysql> alter table topics change hotico hot_count int(4);

mysql> alter table topics alter hot_count set default 1;

補充:

加索引

mysql> alter table 表名 add index 索引名 (欄位名1[,欄位名2 …]);

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

加主關鍵字的索引

mysql> alter table 表名 add primary key (欄位名);

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

加唯一限制條件的索引

mysql> alter table 表名 add unique 索引名 (欄位名);

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

mysql alter語法運用:檢視某個表的索引

mysql> show index from 表名;

例子: mysql> show index from employee;

刪除某個索引

mysql> alter table 表名 drop index 索引名;

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

修改表:增加字段:mysql> alter table table_name add field_name field_type;

檢視表:mysql> select * from table_name;

修改原欄位名稱及型別:mysql> alter table table_name change old_field_name new_field_name field_type;

刪除字段:mysql alter table table_name drop field_name;

本文標題: mysql alter語法的運用方法

本文位址:

MySQL Alter語句 運用

修改表名 mysql alter table student rename person 這裡的student是原名,person是修改過後的名字 用rename來重新命名,也可以使用rename to 修改欄位的資料型別 mysql alter table person modify name v...

mysql ALTER 語句的使用

基本語法 alter online offline ignore tabletbl name alter specification alter specification partition options alter specification table options add column ...

Mysql alter語句的用法

1 刪除列 alter table 表名字 drop 列名稱 2 增加列 alter table 表名字 add 列名稱 int not null comment 注釋說明 3 修改列的型別資訊 alter table 表名字 change 列名稱 新列名稱 這裡可以用和原來列同名即可 bigint...