Automatically exclude calculated field copy table data

Source: Internet
Author: User
Tags copy count sql
Data
This article belongs to Spanzhang original, its blog address is: Http://blog.csdn.net/spanzhang. Quote or paste, please specify the source, thank you!!

/* Author: Zhang Youbang Time: 2005-03-03 Description: Simple copy of the content version of a table: 1.0 history: Note: */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    SE T @sql = n ' Set Identity_insert ' + @tableName + n ' on '     execute sp_executesql @sqlenddeclare @columns NVA Rchar (2048) Set @columns = N ' Select     @columns = @columns + syscolumns.name + N ', ' from sysobjects, syscol Umnswhere sysobjects.id = Syscolumns.id  &nbsP and syscolumns.iscomputed <> 1    and sysobjects.name = @tableNameif len (@columns) > 0 begin&nbsp ;   Set @columns = substring (@columns, 1, Len (@columns)-1) endset @sql = N ' Insert ' + @tableName + n ' (' + @colu MNS + n ') '     + n ' select ' + @columns + n ' from ' + @remoteServer + n '. dbo. ' + @tableNameif @condition ;> n ' begin    set @sql = @sql + n ' where ' + @conditionendexecute sp_executesql @sqlif @count > 0 B egin    Set @sql = N ' Set Identity_insert ' + @tableName + n ' off '     execute sp_executesql @ Sqlend


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.