首页 > 开发 > 综合 > 正文

自动排除计算字段拷贝表数据

2024-07-21 02:05:54
字体:
来源:转载
供稿:网友

本文属spanzhang原创,其blog地址为:http://blog.csdn.net/spanzhang。引用或转贴请注明出处,谢谢!!

/* 作者:张友邦 时间:2005-03-03 描述:简单的拷贝一个表的内容 版本:1.0 历史: 注意:*/alter procedure dbo.x_p_copytable(    @tablename nvarchar(128),    @condition nvarchar(1024) = n'',    @remoteserver nvarchar(128) = n'tgm_old.span_tgm_020')asdeclare @sql nvarchar(4000)set @sql = n'select @cnt = count(*)    from sysobjects, syscolumns    where sysobjects.id = syscolumns.id        and syscolumns.colstat = 1        and sysobjects.name = ''' + @tablename + n''''declare @count intexecute sp_executesql @sql, n'@cnt int output', @count outputif @count > 0 begin    set @sql = n'set identity_insert ' + @tablename + n' on'    execute sp_executesql @sqlenddeclare @columns nvarchar(2048)set @columns = n''select     @columns = @columns + syscolumns.name + n','from sysobjects, syscolumnswhere sysobjects.id = syscolumns.id    and syscolumns.iscomputed <> 1    and sysobjects.name = @tablenameif len(@columns) > 0 begin    set @columns = substring(@columns, 1, len(@columns) - 1)endset @sql = n'insert ' + @tablename + n'(' + @columns + n') '    + n'select ' + @columns + n' from ' + @remoteserver + n'.dbo.' + @tablenameif @condition <> n'' begin    set @sql = @sql + n' where ' + @conditionendexecute sp_executesql @sqlif @count > 0 begin    set @sql = n'set identity_insert ' + @tablename + n' off'    execute sp_executesql @sqlend

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表