读书人

依据 某表的所有字段 创建新表

发布时间: 2012-08-01 17:53:41 作者: rapoo

根据 某表的所有字段 创建新表
根据 某表的所有字段

这个表的所有字段是 根据
select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='Guanxi2') 得到

创建一张新表


那位大哥帮帮忙




-- 判断 触发器是否存在
if exists (select * from dbo.sysobjects where id=object_id(N'[dbo].[Guanxi11]')and OBJECTPROPERTY(id,N'IsTrigger')=1)
drop trigger [dbo].Guanxi11
GO

Create Trigger Guanxi11
On Guanxi1 --在Student表中创建触发器
for Delete --为什么事件触发
As
Begin
if not exists (select * from sysobjects where id = object_id('Guanxi22'))--判断表是否存在
Begin
--不存在创建新表

end
--从内存中把删除的数据插入到此表
insert into Guanxi22 ((select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='Guanxi2'))
select * from Deleted
End

[解决办法]

SQL code
--只创建结构select top 0 * into new_table from old_table 或者select * into newtable from oldtable where 1=2--带数据一起创建 select * into new_table from old_table
[解决办法]
SQL code
直接创建即可:SELECT * INTO 新表名称 FROM Guanxi2 WHERE 1>2
[解决办法]
探讨
根据 某表的所有字段

这个表的所有字段是 根据
select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='Guanxi2') 得到

创建一张新表


那位大哥帮帮忙




-- 判断 触发器是否存在
if exists (sel……

[解决办法]
SQL code
select * into newtable from oldtable where 1<>1 

读书人网 >SQL Server

热点推荐