SQL Server Copying tables from one database to another

前端 未结 7 1186
爱一瞬间的悲伤
爱一瞬间的悲伤 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:42

    Try this:

    If target table is exists :

    SELECT SourceTableAlias.*
    INTO TargetDB.dbo.TargetTable
    FROM  SourceDB.dbo.SourceTable SourceTableAlias
    

    And if target table is not exists :

     INSERT INTO TargetDB.dbo.TargetTable 
     SELECT SourceTableAlias.*
     FROM SourceDB.dbo.SourceTable SourceTableAlias
    

    Good Luck!

提交回复
热议问题