新建了一个表,没有设置主键和索引,但在输入数据(通过insert语句)后,表中记录的顺序却不按照输入的顺序保存,有什么办法可以让表中的数据能按输入的先后顺序保存?

解决方案 »

  1.   

    理解数据库记录的存储,其存储物理顺序依赖蔟索引设计
    检索结果如果没有order指令,就是无序的
      

  2.   

    设置一个ID   int  IDENTITY(1,1) NOT NULL就可以了。
      

  3.   

      alter table tb
      add id int identity(1,1) 
      

  4.   

    没有索引和主键的话,应该是按插入的顺序排列。LZ再仔细检查一下?
    if object_id('tb') is not null 
    drop table tb
    go
    create table tb(c int)
    insert tb values(3)
    insert tb values(14)
    insert tb values(5)
    insert tb values(60)
    insert tb values(1)
    insert tb values(4)select * from tb
    /*
    c
    -----------
    3
    14
    5
    60
    1
    4(6 row(s) affected)*/
      

  5.   

    会不会在列上已经创建了主键之类?
    if object_id('tb') is not null 
        drop table tb
    go
    create table tb(c int primary key)
    insert tb values(3)
    insert tb values(14)
    insert tb values(5)
    insert tb values(60)
    insert tb values(1)
    insert tb values(54)select * from tb
    ----------------
    c           
    ----------- 
    1
    3
    5
    14
    54
    60
      

  6.   

    可以按顺序保存,不要一下保存多条数据
    一般会按顺序显示,不用order排序,但这不提倡,随机事情太多
    介意建立索引,或者建一个identity列
      

  7.   

    建一个identity列(自动增长列)