SQL Server将表从一个数据库复制到另一个数据库 [英] SQL Server Copying tables from one database to another

查看:67
本文介绍了SQL Server将表从一个数据库复制到另一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数据库,一个数据库称为 Natalie_playground ,一个数据库称为 LiveDB
因为我想练习插入,更新事物,所以我想将某些表从 LiveDB 复制到 Natalie_playground

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 some of the tables from the LiveDB to Natalie_playground.

我要复制的表格称为:
客户,计算机,手机,价格

The tables I want to copy are called: Customers, Computers, Cellphones, Prices

我想做的是(使用SSMS)右键单击表格,但是其中没有复制!

What I tried to do is that (using SSMS) right click on a table but there is no Copy in there!

推荐答案

假定您有两个数据库,例如A和B:

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.

    这篇关于SQL Server将表从一个数据库复制到另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆