mysql> desc tbb;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| rid | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.02 sec)
mysql> alter table tbb change column id ridd int(11);
Query OK, 7 rows affected (0.13 sec)
Records: 7 Duplicates: 0 Warnings: 0mysql> select * from tbb;
+------+------+
| ridd | rid |
+------+------+
| 1 | 78 |
| 2 | 64 |
| 2 | 78 |
| 3 | 78 |
| 4 | 78 |
| 4 | 64 |
| 4 | 56 |
+------+------+
7 rows in set (0.00 sec)mysql> alter table tbb change column rid id int(11);
Query OK, 7 rows affected (0.13 sec)
Records: 7 Duplicates: 0 Warnings: 0mysql> alter table tbb change column ridd rid int(11);
Query OK, 7 rows affected (0.14 sec)
Records: 7 Duplicates: 0 Warnings: 0mysql> select * from tbb;
+------+------+
| rid | id |
+------+------+
| 1 | 78 |
| 2 | 64 |
| 2 | 78 |
| 3 | 78 |
| 4 | 78 |
| 4 | 64 |
| 4 | 56 |
+------+------+
7 rows in set (0.00 sec)参考下
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| rid | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.02 sec)
mysql> alter table tbb change column id ridd int(11);
Query OK, 7 rows affected (0.13 sec)
Records: 7 Duplicates: 0 Warnings: 0mysql> select * from tbb;
+------+------+
| ridd | rid |
+------+------+
| 1 | 78 |
| 2 | 64 |
| 2 | 78 |
| 3 | 78 |
| 4 | 78 |
| 4 | 64 |
| 4 | 56 |
+------+------+
7 rows in set (0.00 sec)mysql> alter table tbb change column rid id int(11);
Query OK, 7 rows affected (0.13 sec)
Records: 7 Duplicates: 0 Warnings: 0mysql> alter table tbb change column ridd rid int(11);
Query OK, 7 rows affected (0.14 sec)
Records: 7 Duplicates: 0 Warnings: 0mysql> select * from tbb;
+------+------+
| rid | id |
+------+------+
| 1 | 78 |
| 2 | 64 |
| 2 | 78 |
| 3 | 78 |
| 4 | 78 |
| 4 | 64 |
| 4 | 56 |
+------+------+
7 rows in set (0.00 sec)参考下
解决方案 »
- 求一个sql语句, 谢谢大家 :)
- [求助]怎样把MYSQL数据库的JDBC驱动程序加入到WEBLOGIC SERVER的CLASSPATH
- mysql 多个型号建表疑惑
- 一个关于mySQL jdbc 性能的疑问
- decimal(9)类型设置成自增是否可以?目前导入Mysql的时候报错!
- 刚接触MySQL5.0,我已经装了图形工具,但在MSDOS下如何使用命令行来操作数据库?如何进入工作状态?
- mysql的数据容量有多大,sqlserver的有多大,谁的的大?
- linux下安装mysql的最后关头出现问题
- 怎么把 ShutDown this Tool 用命令行来代替?
- mysql command line client打不开(闪一下消失)
- 类似与这样的表 如果 要修改 field里面的字段名字 改如何修改?
- mysql 查询50W条记录的表,怎么优化
mysql> select * from tbb;
+------+------+
| rid | id |
+------+------+
| 1 | 78 |
| 2 | 64 |
| 2 | 78 |
| 3 | 78 |
| 4 | 78 |
| 4 | 64 |
| 4 | 56 |
+------+------+
7 rows in set (0.00 sec)mysql> select id,rid from tbb;
+------+------+
| id | rid |
+------+------+
| 78 | 1 |
| 64 | 2 |
| 78 | 2 |
| 78 | 3 |
| 78 | 4 |
| 64 | 4 |
| 56 | 4 |
+------+------+
7 rows in set (0.00 sec)
mysql> create temporary table tt select id,rid from tbb;
Query OK, 7 rows affected (0.06 sec)
Records: 7 Duplicates: 0 Warnings: 0mysql> desc tbb;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| rid | int(11) | YES | | NULL | |
| id | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)mysql> desc tt;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| rid | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)
Query OK, 7 rows affected (0.14 sec)
Records: 7 Duplicates: 0 Warnings: 0mysql> desc tbb;
+-------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| rid | int(11) | YES | | NULL | |
+-------+---------+------+-----+---------+-------+
2 rows in set (0.00 sec)
版主好强大
mysql> select * from tbb;
+------+------+
| id | rid |
+------+------+
| 78 | 1 |
| 64 | 2 |
| 78 | 2 |
| 78 | 3 |
| 78 | 4 |
| 64 | 4 |
| 56 | 4 |
+------+------+
7 rows in set (0.00 sec)mysql> alter table tbb modify rid int(11) first;
Query OK, 7 rows affected (0.14 sec)
Records: 7 Duplicates: 0 Warnings: 0mysql> select * from tbb;
+------+------+
| rid | id |
+------+------+
| 1 | 78 |
| 2 | 64 |
| 2 | 78 |
| 3 | 78 |
| 4 | 78 |
| 4 | 64 |
| 4 | 56 |
+------+------+
7 rows in set (0.00 sec)自己好好看看
姓名 身份证 两个里面的内容交换 会出现长度不够的错误 里面的内容根本没有变啊 例如 姓名(varchar(10) 身份证 int(20)
我 435435465546
你 432432452454645
他 54356356654542
+------+-----------------+
| 姓名 | 身份证 |
+------+-----------------+
| WW | 435435465546 |
| SS | 432432452454645 |
| AA | 54356356654542 |
+------+-----------------+
3 rows in set (0.00 sec)mysql> alter table t_hiphopthehook MODIFY 姓名 varchar(10) after 身份证 ;
Query OK, 3 rows affected (0.13 sec)
Records: 3 Duplicates: 0 Warnings: 0mysql> select * from t_hiphopthehook;
+-----------------+------+
| 身份证 | 姓名 |
+-----------------+------+
| 435435465546 | WW |
| 432432452454645 | SS |
| 54356356654542 | AA |
+-----------------+------+
3 rows in set (0.00 sec)mysql>