--转移数据 select ID,name,age into # from a --删除原来的表 delete a --插入a表 select * into a from #
--转移数据 select ID,name,age into # from a --删除原来的表 drop table a --插入a表 select * into a from # 修改
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楼阿。。 语句顺序变好了啊 select ID,name,age into # from a --删除原来的表 drop table a --插入a表 select * into a from #
-- ========================================= -- -----------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*/
然后改名吧
select ID,name,age
into #
from a
--删除原来的表
delete a
--插入a表
select *
into a
from #
select ID,name,age
into #
from a
--删除原来的表
drop table a
--插入a表
select *
into a
from #
修改
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楼阿。。
语句顺序变好了啊
select ID,name,age
into #
from a
--删除原来的表
drop table a
--插入a表
select *
into a
from #
-- -----------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*/