mysql中alter语句中change和modify的区别[转]

以下摘自mysql5手册

您可以使用CHANGE old_col_namecolumn_definition子句对列进行重命名。重命名时,需给定旧的和新的列名称和列当前的类型。例如:要把一个INTEGER列的名称从a变更到b,您需要如下操作:

·                mysql> ALTER TABLE t1 CHANGE a b INTEGER;

如果您想要更改列的类型而不是名称, CHANGE语法仍然要求旧的和新的列名称,即使旧的和新的列名称是一样的。例如:

mysql> ALTER TABLE t1 CHANGE b b BIGINT NOT NULL;

您也可以使用MODIFY来改变列的类型,此时不需要重命名:

mysql> ALTER TABLE t1 MODIFY b BIGINT NOT NULL;

mysql alter 语句用法,添加、修改、删除字段等 

//主键549830479

alter table tabelname add new_field_id int(5) unsigned default 0 not null auto_increment ,add primary key (new_field_id);
//增加一个新列549830479

alter table t2 add d timestamp;
alter table infos add ex tinyint not null default ‘0’;
//删除列549830479

alter table t2 drop column c;
//重命名列549830479

alter table t1 change a b integer;

//改变列的类型549830479

alter table t1 change b b bigint not null;
alter table infos change list list tinyint not null default ‘0’;

//重命名表549830479

alter table t1 rename t2;
加索引549830479

mysql> alter table tablename change depno depno int(5) not null;
mysql> alter table tablename add index 索引名 (字段名1[,字段名2 …]);
mysql> alter table tablename add index emp_name (name);
加主关键字的索引549830479

mysql> alter table tablename add primary key(id);
加唯一限制条件的索引549830479

mysql> alter table tablename add unique emp_name2(cardnumber);
删除某个索引549830479

mysql>alter table tablename drop index emp_name;
修改表:549830479

增加字段:549830479

mysql> ALTER TABLE table_name ADD field_name field_type;
修改原字段名称及类型:549830479

mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;
删除字段:549830479

mysql> ALTER TABLE table_name DROP field_name;

删除主键: alter table Employees drop primary key;

47 thoughts on “mysql中alter语句中change和modify的区别[转]

  1. Pingback: black pop culture t shirt

  2. Pingback: Watch The Mule Free Online

  3. Pingback: 바카라사이트

  4. Pingback: http://biegoryj.pl/rynek-instalacyjny-1-2-2016-2500.php

  5. Pingback: con heo dat remix

  6. Pingback: forum

  7. Pingback: cbd

  8. Pingback: best CBD oil

  9. Pingback: i99 casino

  10. Pingback: ปรึกษา เรื่อง เงิน

  11. Pingback: fun 88

  12. Pingback: kristal qq

  13. Pingback: https://bravo.edu.pl/

  14. Pingback: اخبار

  15. Pingback: 안전바카라

  16. Pingback: custom bass boat carpet decals

  17. Pingback: sahabatqq

  18. Pingback: porn

  19. Pingback: 바카라

  20. Pingback: Replica Handbags

  21. Pingback: https://funkymedia.pl/

  22. Pingback: fake good iwc clone

  23. Pingback: एक्स एक्स एक्स वीडियो

  24. Pingback: 바카라 사이트 먹튀

  25. Pingback: http://199.192.19.81/

  26. Pingback: Carry the Flame - A Heartfelt Thank You to Everyday Heroes of the COVID-19 Pandemic

  27. Pingback: ciproxin dosage

  28. Pingback: richard mille yas marina replica

  29. Pingback: viagra online canadian pharmacy

  30. Pingback: ربح المال من الانترنت بالمغرب 2020

  31. Pingback: Dictator Dirk

  32. Pingback: Types Of Fishing Poles

  33. Pingback: men over 50 viagra heart condition

  34. Pingback: the asigo system reviews

  35. Pingback: california.perfecthealth101.net

  36. Pingback: kalpa pharma steroids legit

  37. Pingback: สินเชื่อพิโกไฟแนนซ์

  38. Pingback: plumber near me in Tulse

  39. Pingback: afro wigs

  40. Pingback: uniccshop.bazar

  41. Pingback: ghi so de

  42. Pingback: 토토사이트

  43. Pingback: cbd oil gummies

  44. Pingback: w88

  45. Pingback: https://www.jueriy.com

  46. Pingback: 토토사이트

  47. Pingback: cialis for sale

Comments are closed.