表的结构为:
mysql> desc t_role;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(11)      | NO   | PRI | NULL    | auto_increment |
| name  | varchar(255) | NO   | UNI | NULL    |                |
+-------+--------------+------+-----+---------+----------------+
查询数据结果:
mysql> select * from t_role;
+----+-----------+
| id | name      |
+----+-----------+
|  4 | scriptguy |
|  3 | 模块1     |
|  2 | 暖暖的    |
+----+-----------+
3 rows in set (0.00 sec)
请问这是为什么呢?

解决方案 »

  1.   

    记录的插入后的物理顺序是由MYSQL来控制了。数据库原理中的一个重要理论就是集合中的元组是没有顺序 的。输出的顺序要由你自己通过ORDER BY 来控制。
      

  2.   


    一般看到的插入都是在最末位的位置,应该是最后一行。
    查询的排序由ORDER BY控制,插入的物理位置由MYSQL控制,但楼主的控制和一般的是不一样的,估计是哪个参数配置的问题。求答案
      

  3.   

    某些数据删除过?
    mysql> insert into t1 values(1), (2), (3);
    Query OK, 3 rows affected (0.03 sec)
    Records: 3  Duplicates: 0  Warnings: 0mysql> select * from t1;
    +------+
    | id   |
    +------+
    |    1 |
    |    2 |
    |    3 |
    +------+
    3 rows in set (0.03 sec)mysql> delete from t1 where id = 2;
    Query OK, 1 row affected (0.02 sec)mysql> insert into t1 values(2);
    Query OK, 1 row affected (0.00 sec)mysql> select * from t1;
    +------+
    | id   |
    +------+
    |    1 |
    |    3 |
    |    2 |
    +------+
    3 rows in set (0.00 sec)mysql> delete from t1 where id = 1;
    Query OK, 1 row affected (0.00 sec)mysql> insert into t1 values(1);
    Query OK, 1 row affected (0.00 sec)mysql> select * from t1;
    +------+
    | id   |
    +------+
    |    3 |
    |    2 |
    |    1 |
    +------+
    3 rows in set (0.00 sec)mysql>
      

  4.   

    总之select出来,不带排序的数据,它的顺序只与DBMS读取时的顺序有关。
      

  5.   


    恩,现在明白了,不加order by的话mysql不保证按顺序输出结果集。
    谢谢回帖