日期:2014-05-18  浏览次数:20619 次

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

这个表的所有字段是 根据 
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