假设我有个个表a  有 id age name 字段,现在要在表里面改变字段顺序id,name,age是永久改变。哪位高手知道怎么写sql代码??谢谢了啊

解决方案 »

  1.   

    麻烦,直接select id,name,age into tmp from ta
    然后改名吧
      

  2.   

    --转移数据
    select ID,name,age 
    into # 
    from a
    --删除原来的表
    delete  a
    --插入a表
    select * 
    into a 
    from #
      

  3.   

    --转移数据
    select ID,name,age 
    into # 
    from a
    --删除原来的表
    drop table  a
    --插入a表
    select * 
    into a 
    from #
    修改
      

  4.   

    create table ta(id int,col char(100))
     
    goselect * from taselect * from syscolumns where id = object_id('ta')
     
    exec sp_configure 'allow update',1
    go
    reconfigure with override
    goupdate syscolumns
    set colid = 3 
    where id = object_id('ta') and name = 'col' 
    update syscolumns
    set colid = 2 
    where id = object_id('ta') and name = 'id' update syscolumns
    set colid = 1 
    where id = object_id('ta') and name = 'col' 
    exec sp_configure 'allow update',0
    go
    reconfigure with override
    go
    select * from ta
     drop table ta,tb
      

  5.   

    \
    看5楼阿。。
    语句顺序变好了啊
    select ID,name,age 
    into # 
    from a
    --删除原来的表
    drop table  a
    --插入a表
    select * 
    into a 
    from #
      

  6.   

    -- =========================================
    -- -----------t_mac 小编-------------------
       --------------------希望有天成为大虾---- 
    -- =========================================IF OBJECT_ID('a') IS NOT NULL
    DROP TABLE a
    GO
    CREATE TABLE a(  id  int,age int, name  varchar(10))
    go
    insert a SELECT 1,12,'a' 
    UNION ALL SELECT 2,13,'b'
    goselect ID,name,age 
    into # 
    from a 
    --删除原来的表 
    drop table  a  
    --插入a表 
    select * 
    into a 
    from #
    go
    select * from a
    /*
    ID          name       age
    ----------- ---------- -----------
    1           a          12
    2           b          13*/
      

  7.   

    好了  哈哈 谢谢各位高手的帮助,麦蒂的操作简单h,appyflystone的 我也学习下 ,谢谢啦 只是分数少了点,不好意思了