Copy data between databases with the same structure

Source: Internet
Author: User
There is no replicate between databases with the same structure. Schema_name (sst. schema_id) FROMsys. tablessstWHEREsst. TYPEUDECLARE @ nameVARCHAR (80), @ schemaVARCHAR (40) OPENNoCheckConstr

There is no use oldgoDECLARE NoCheckConstraintAll CURSOR READ_ONLY for select sst between databases with the same structure. name, Schema_name (sst. schema_id) FROM sys. tables sst WHERE sst. TYPE = 'U' DECLARE @ name VARCHAR (80), @ schema VARCHAR (40) OPEN NoCheckConstr

Copy data between databases with the same structure <无>
use oldgoDECLARE NoCheckConstraintAll CURSOR READ_ONLY FOR   SELECT sst.name,          Schema_name(sst.schema_id)   FROM   sys.tables sst   WHERE  sst.TYPE = 'U' DECLARE @name   VARCHAR(80),         @schema VARCHAR(40)OPEN NoCheckConstraintAllFETCH NEXT FROM NoCheckConstraintAll INTO @name, @schemaWHILE ( @@FETCH_STATUS <> -1 )   BEGIN       IF ( @@FETCH_STATUS <> -2 )         BEGIN                 DECLARE @sql NVARCHAR(1024) SET @sql=' ALTER TABLE ' + Quotename(@schema)                            +                            '.' + Quotename(@name)+' NOCHECK CONSTRAINT ALL'                  EXEC Sp_executesql @sql         END      FETCH NEXT FROM NoCheckConstraintAll INTO @name, @schema   ENDCLOSE NoCheckConstraintAllDEALLOCATE NoCheckConstraintAllGODECLARE CopyTables CURSOR READ_ONLY FOR   SELECT sst.name,          Schema_name(sst.schema_id)   FROM   sys.tables sst   WHERE  sst.TYPE = 'U' DECLARE @name   VARCHAR(80),         @schema VARCHAR(40)OPEN CopyTablesFETCH NEXT FROM CopyTables INTO @name, @schemaWHILE ( @@FETCH_STATUS <> -1 )   BEGIN       IF ( @@FETCH_STATUS <> -2 )         BEGIN                 DECLARE @sql NVARCHAR(1024) SET @sql='INSERT INTO [new].' + Quotename(@schema)                            +                            '.' + Quotename(@name)+' SELECT * FROM '+ Quotename(@schema)                            +                            '.' + Quotename(@name)                  EXEC Sp_executesql @sql         END      FETCH NEXT FROM CopyTables INTO @name, @schema   ENDCLOSE CopyTablesDEALLOCATE CopyTablesGODECLARE CheckConstraintAll CURSOR READ_ONLY FOR   SELECT sst.name,          Schema_name(sst.schema_id)   FROM   sys.tables sst   WHERE  sst.TYPE = 'U' DECLARE @name   VARCHAR(80),         @schema VARCHAR(40)OPEN CheckConstraintAllFETCH NEXT FROM CheckConstraintAll INTO @name, @schemaWHILE ( @@FETCH_STATUS <> -1 )   BEGIN       IF ( @@FETCH_STATUS <> -2 )         BEGIN                 DECLARE @sql NVARCHAR(1024) SET @sql=' ALTER TABLE ' + Quotename(@schema)                            +                            '.' + Quotename(@name)+' CHECK CONSTRAINT ALL'                  EXEC Sp_executesql @sql         END      FETCH NEXT FROM CheckConstraintAll INTO @name, @schema   ENDCLOSE CheckConstraintAllDEALLOCATE CheckConstraintAllGO

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.