对数据表添加新列到指定位置

首先:

--创建测试环境
create table TEST
(
  A varchar(20),
  B varchar(20),
  C varchar(20)
)
go

--允许系统标更新
exec sp_configure 'allow updates','1'
go
reconfigure with override
go

--添加D列
alter table test add D varchar(10)

--更新B,C列顺序
update syscolumns 
set colid=colid+1
where colid>=2 and id=object_id('test')

--更新D列顺序
update syscolumns 
set colid=2
where name='D' and id=object_id('test')

--禁用系统标更新
exec sp_configure 'allow updates','0'
go
reconfigure with override
go

posted on 2012-12-08 15:53  幻林的地盘  阅读(283)  评论(0编辑  收藏  举报

导航