在时间字段里一个排序啊  desc的

解决方案 »

  1.   

    我在企业管理器里,找了很久:
    一、找到那个register_user表后,右键点击“属性”,在出现的“全文索引”里,找不到升降序项啊!
    二、找到那个表register_user表后,点“重新设计表”,找到register_time这个时间字段项,也没有升降序项啊!在企业管理器里,在哪儿能找到升降序啊!请原谅初学者的无知,谢谢。
      

  2.   

    你的表应该是个堆集,就是没有建立聚集索引。表按聚集索引字段所规定的顺序保存数据,如果你没有聚集索引,新插入的数据会选择空页保存。所以在没有聚集索引的情况下,不能保证后插入的数据就排在后面。create table csdn2(rid int identity(1,1),
    username varchar(32) ,
    writetime datetime)
    go
    insert into csdn2(username,writetime) values('user1',getdate())
    insert into csdn2(username,writetime) values('user2',getdate())
    insert into csdn2(username,writetime) values('user3',getdate())
    select * From csdn2
    delete from csdn2 where username = 'user2'
    select * From csdn2
    insert into csdn2(username,writetime) values('user4',getdate())
    select * From csdn2--最后一个select的结果是,user4 被存储在 user2 的位置上
    1 user1 2005-12-28 22:05:21.683
    4 user4 2005-12-28 22:05:55.967
    3 user3 2005-12-28 22:05:31.373---------------------------------------
    http://chinadba.cn
    最具实战经验的数据库优化,管理,设计,培训网
    访问大提速!
      

  3.   

    明白骄子兄的话了。谢谢。我是先把原空间的数据库生成sql语句,再在新空间生成表结构,再导入数据的。我并没有动过什么啊?产生这样的问题,很可能是丢了什么了。原数据库肯定有索引,我该怎么发现新空间没有索引呢?如何补上这索引?----不胜感激。
      

  4.   

    sp_helpindex tablename 
    go
    可以查看有没有索引。如果你的聚集索引(cluster index ) 没有建在时间字段上,那你必须通过 order by time_column 字段来保证正确的顺序。你的情况可以通过排序来解决。---------------------------------------
    http://chinadba.cn
    最具实战经验的数据库优化,管理,设计,培训网
    访问大提速!
      

  5.   

    非常感谢骄子兄的指导。我已经查看了索引,索引没建在时间字段上,而是建在 User_id 用户注册号这个字段上。并且是非聚集索引。原空间的索引和新空间的索引,我对比了一下,情况是一样的。索引的查看结果:
    index_name:PK_register_user
    index_description:nonclustered,unique,primary ke...
    index_keys:user_id
    解决问题的一个方法,可能就是重建索引。它的语法格式,我不大清楚,请各位指导。我把要执行的命令写在下面,请指点:
    use nameofdbc
    go
    create index PK_register_user
    on register_user(user_id)
    with drop_existing
      

  6.   

    在下又看了一下进行查询的网页,网页源代码,确如骄子兄所说,是按注册时间降序排列的:order by register_time desc.这并没错啊,网页代码是复制过来的,网站数据库是复制过来的,怎么会出现这样错误呢?困惑啊!请指点迷津,谢谢。
      

  7.   

    被你弄糊涂了
    你如果确实用了 order by register_time desc的话,显示一定会是按照 register_time 倒序啊难道你的 register_time 不是 datetime  类型而是 varchar ?---------------------------------------
    http://chinadba.cn
    最具实战经验的数据库优化,管理,设计,培训网
      

  8.   

    能与骄子兄这样的高手请教,真是荣幸啊。请骄子兄,审查下面的网页源代码,copy过来的,应该不会有问题:
    <%mytitle="查询商家"
    dim page
    page=request("page")
    if isempty(page) then
          page=1
    end ifif request("province")<>"" then
    province=request("province")
    session("province")=province
    end if
    province=session("province")if request("goto_name")<>"" then
    goto_name=request("goto_name")
    session("goto_name")=goto_name
    end if
    goto_name=session("goto_name")if request("goto_all_id")=1 then
    province=""
    session("province")=""
    goto_name=""
    session("goto_name")=""
    end ifif  province="" and goto_name=""  then
           sqltext="select * from  register_user a,class b   where  "
       sqltext=sqltext&" a.person_manage=b.class_id and b.parent=0 "
       sqltext=sqltext&"  order by register_time desc"
    end ifif  province<>""   then
           sqltext="select * from  register_user a,class b   where  "
       sqltext=sqltext&" a.person_manage=b.class_id and b.parent=0 "
       sqltext=sqltext&"  and a.province like '%"&province&"%'  order by register_time desc"
    end ifif  goto_name<>""   then
          sqltext="select * from  register_user a,class b   where  "
       sqltext=sqltext&" a.person_manage=b.class_id and b.parent=0 "
       sqltext=sqltext&"  and a.company_name like '%"&goto_name&"%'  order by register_time desc"
    end if       set rs=server.createobject("adodb.recordset")
           rs.open sqltext,conn,1,1
           rs.PageSize=13
          if rs.recordcount>0 then
          If page<1 or (page-1)*rs.pagesize>=rs.recordcount then
             page=1
          End If
           rs.absolutepage=cint(page)
    end if
       
    %>
    <html>
    <head>
    <META content="text/html; charset=gb2312" http-equiv=Content-Type><title>查询商家</title>
    <meta content="text/html; charset=gb2312" http-equiv="Content-Type">
    <meta content="Microsoft FrontPage 5.0" name="GENERATOR">
    <!--#include file="mall/include/style.css" -->
    </head>
    <body leftmargin="0"><!--#include file="top.asp"-->
    <table border="0" width="765" height="313" cellspacing="1" align="center">
      <tr>
        <td width="152" height="307" valign="top" align="center" bgcolor="#FFFFFF">
        <!--#include file="company_left.asp"-->
        </td>
        <td width="583" height="307" valign="top" bgcolor="#FFFFFF">
         <TABLE cellSpacing=1 cellPadding=2 width="573"  align=center 
                bgColor=#b2927e border=0><TBODY>
                  <TR><TD bgColor=#f7e3d3 height=20><form method="POST"   action="company_browse.asp"  name="form5"><table ><tr>
    <td height=20><font color="#000000" size="2">商家名称:</font><input type=text class="rec_form" name="goto_name" value="<%=goto_name%>" size=20   tabindex=1>  <input type=submit value=查询  class="rec_form" name=B1 tabindex=2></form> </td><td><form method="POST"   action="company_browse.asp?goto_all_id=1"  name="form4"><font size="2"> 
    <input type=submit value=全部查询 class="rec_form" name=B1 tabindex=2>  
    </font></form></td></tr></table></td></tr></table> 
    <table border="0" >  
      <tr > 
          <td height="1" ><font size="2">
     <%response.write "<a href='company_browse.asp?page="&page&"'>刷新浏览</a>&nbsp;"  
     if rs.pagecount=0 then                                                              
        Response.Write "首页&nbsp; 前页&nbsp; 后页&nbsp; 末页&nbsp; 页次0/0页"                                                                                                                                                                   
       elseif rs.Pagecount=1 then                                                                                                                                                                   
        Response.Write "首页&nbsp; 前页&nbsp; 后页&nbsp; 末页&nbsp; 页次1/1页"                                                                                                                                                                   
        elseif page=1 then                                                                                                                                                                   
        Response.Write "首页&nbsp; 前页&nbsp;<a href='company_browse.asp?page="&page+1&"'>后页</a>&nbsp;<a href='company_browse.asp?page="&rs.PageCount &"'>末页</a>&nbsp;页次"&Page&"/"&rs.pagecount&"页"                                                                                                                                                                   
        elseif rs.PageCount=cint(Page) then                                                                                                                                                                   
        Response.Write "<a href='company_browse.asp?page=1'>首页</a>&nbsp;<a href='company_browse.asp?page="&page-1&"'>前页</a>&nbsp;后页&nbsp;末页&nbsp;页次"&Page&"/"&rs.pagecount&"页"                                                                                                                                                                   
        else                                                                                                                                                                   
        Response.Write "<a href='company_browse.asp?page=1'>首页</a>&nbsp;<a href='company_browse.asp?page="&page-1&"'>前页</a>&nbsp;<a href='company_browse.asp?page="&page+1&"'>后页</a>&nbsp;<a href='company_browse.asp?page="&rs.PageCount&"'>末页</a>&nbsp;页次"&Page&"/"&rs.pagecount&"页"                                                                                                                                                                   
        end if                                                                                                                                                                   
     response.write "共<font color='#FF0000'>"&rs.RecordCount&"</font>条记录"
     %>  
            </font>  
    </td>  
        </tr>  
      </table>  
    <table align="left" border="1" borderColorDark="#ffffff" borderColorLight="#000000" cellPadding="3" cellSpacing="0"  width="581" height="42"  >  
    <TBODY>  
      <tr bgColor="#E1D9F7">  
        <td  bgcolor="#0099CC" width="341" valign="bottom" height="13"><font color="#000000" size="2"><img border="0" src="image/housewares.gif" align="bottom"></font><font color="#FFFFFF" size="2"> 商家名称(点名称即可进入)</font><font color="#FFFFFF">
        </font> </td>  
        <td  bgcolor="#0099CC" width="222" valign="bottom" height="13"><font color="#000000" size="2"><img border="0" src="image/product_manage.gif" align="bottom"></font><font color="#FFFFFF" size="2"> 主营业务</font></td>  
      </tr>  
    <%if not rs.recordcount=0 then  
           for j=1 to rs.pagesize%>  
      <tr>  
        <td width="341" height="13" ><a href="new_company.asp?suser_id=<%=rs("user_id")%>"><font size="2" color="#000000"> <%=rs("company_name")%></font></a> </td> 
        <td width="222" valign="bottom" height="13" ><font size="2"> <font color="#000000"> <%=rs("class_name")%></font></font></td>  
      </tr>  
    <%  
         rs.MoveNext  
             if rs.eof then  
                exit for  
             end if  
          next  
       end if  
      
    %>  
    </TBODY>  
    </table> 
    <br>
    </td>
      </tr>
    </table>  </body>
    </html>
      

  9.   

    我只能建议你调试一下。
    你在asp里,把 sqltext 打印出来,在查询分析器里执行一下,看有多少条数据。顺序是怎么样的?
    注意一定要执行打印出来的语句。这没有什么特异的东西在里面,一定是你弄错了。可能是以前导的数据,没有register_time
    还有,你把2个表的表结构贴出来吧。
      

  10.   

    如果只数据库位置发生迁移 请比较两个数据库的排序规则(collation) 不同的排序下 order by的结果可能是不同的