数据不按顺序插入怎么回事?我想按照我原来录入的数据顺序录入到数据库中,但是当我查询出来后发现循序都是按照字母顺序显示的.但是现在我想要显示出来的按原来的循序显示,该怎么做?
如:录入的一个字段(主键)a,d,c .然后我要显示出来后也为a,d,c. 但是现在显示的顺序为a ,c,d.

解决方案 »

  1.   

    create table A
    (
       id indentity(1,1)   num int
    )select * from A where id in(3,1,2)select * from A where id in(3,1,2)
    order by charindex(','+rtrim(id)+',',',3,1,2,')
      

  2.   

    应该和主键有关系
    create table a(a varchar(1) primary key)
    insert into a select 'a'
    insert into a select 'd'
    insert into a select 'c'select * from acreate table b(b varchar(1))
    insert into b select 'a'
    insert into b select 'd'
    insert into b select 'c'select * from bdrop table a,b
      

  3.   

    1.主键上默认有聚集索引,聚集索引确定表中数据的物理顺序
    2.在没有order by的情况下,sqlserver不保证查询结果的顺序
    3.楼主的问题可以通过加identity列来解决
      

  4.   

    添加IDENTITY列,然后 select ... order by identity列