注册 登录
编程论坛 SQL Server论坛

如何在表中固定位置插入列

yan3829298 发布于 2007-03-31 16:50, 658 次点击
请问如何在SQL,如有表TEST,有(ABC)列,如在A与B之间插入D列,即是(ADBC)列,谢谢!
3 回复
#2
棉花糖ONE2007-03-31 17:06

这样的话只能插入d列后改系统表

#3
棉花糖ONE2007-03-31 17:07

通过系统表改列的物理顺序
if object_id('shiyan') is not null
drop table shiyan
go
create table shiyan(id int,name varchar(10),score int)
insert into shiyan select 1,'aa',80

sp_configure 'allow update',1
reconfigure with override
select a.name,colid from syscolumns a,sysobjects b where a.id=b.id and b.name='shiyan'
update syscolumns set syscolumns.colid=5 from sysobjects b where syscolumns.id=b.id and b.name='shiyan' and syscolumns.colid=1 --5可以随便改,只要比列的个数大的数就行
update syscolumns set syscolumns.colid=1 from sysobjects b where syscolumns.id=b.id and b.name='shiyan' and syscolumns.colid=3
update syscolumns set syscolumns.colid=3 from sysobjects b where syscolumns.id=b.id and b.name='shiyan' and syscolumns.colid=5
select a.name,colid from syscolumns a,sysobjects b where a.id=b.id and b.name='shiyan'
sp_configure 'allow update',0
reconfigure with override
你参考一下我这个方法

#4
jiushiwo2007-04-10 22:35
暂时还看不懂
1