SQL Server Copying tables from one database to another

前端 未结 7 1169
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-20 16:56

I have two databases, one is called Natalie_playground and one is called LiveDB. Since I want to practice insert, update things, I want to copy som

相关标签:
7条回答
  • 2020-12-20 17:53

    Assuming that you have two databases, for example A and B:

    • If target table not exists, the following script will create (I do not recommend this way):

      SELECT table_A.FIELD_1, table_A.FIELD_2,......, table_A.FIELD_N 
      INTO COPY_TABLE_HERE 
      FROM  A.dbo.table_from_A table_A
      
    • If target table exists, then:

       INSERT INTO TABLE_TARGET 
       SELECT table_A.FIELD_1, table_A.FIELD_2,......, table_A.FIELD_N 
       FROM  A.dbo.table_from_A table_A
      

    Note: if you want learn and practice this, you can use previous scripts, but if you want copy the complete structure and data from database to another, you should use, "Backup and restore Database" or, "Generate Script Database with data" and run this into another database.

    0 讨论(0)
提交回复
热议问题