表中字段顺序无所谓,select时排一下就是啦

解决方案 »

  1.   

    可能我表达有误
    有一表,表中有 a,b,c 三列 现在插入一列d ,要求d插入在a,b中间。怎么写SQL语句。 
    还有。如果要求a,c 列互换(列中的数据也互换),怎么写SQL语句?
      

  2.   

    那就借助中间表怎么样?
    select * into #t from 表
    drop table 表
    create table 表(a,d,b,c)--类型注意
    insert 表
    select a,'d的默认值',b,c from #tdrop table #t
      

  3.   

    哎,可怜的人啊,怎么会用到字段的顺序的呢?
    我以前也遇到过这样问题的,结果是把程序改了。
    :)
    HOHO
      

  4.   

    --如果很有必要的话:  
    --在指定字段后插入字段  
    exec  sp_configure  'allow  updates',1  reconfigure  with  override  
    go  
    alter  table  表  add  id  int    --添加字段  
    go  
    --处理字段位置  
    declare  @colid  int  
    select  @colid=colid  from  syscolumns    
    where  id=object_id('你要修改的表名')  and  name='字段名'--在该字段后插入  
    if  @colid  is  null  set  @colid=1  
    update  syscolumns  set  colid=colid+1  
    where  id=object_id('你要修改的表名')  and  colid  >@colid  
    update  syscolumns  set  colid=@colid+1  
    where  id=object_id('你要修改的表名')  and  colid=(  
               select  max(colid)  from  syscolumns    
               where  id=object_id('你要修改的表名'))  
    go  
    exec  sp_configure  'allow  updates',0  reconfigure  with  override