将表从一个数据库复制到同一服务器中的另一个数据库 [英] Copy a table from one database to another in the same server

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

问题描述

我有两个数据库,分别是"A"和"B".
我需要将表(连同行,Pk,Fk,索引,统计信息)从数据库"A"复制到"B".



您能帮我解决

I have two database namely "A" and "B".
I need to copy a table(along with rows,Pk,Fk,Indexes,statistics) from database "A" to "B".



Can u help me to solve

推荐答案

通过替换Destination,Source数据库和相应的表名在服务器中运行此查询:


从SourceDatabse.dbo.Table选择*到DestinationDatabase.dbo.Table

例如,

从EmployeeDB.dbo.AddressTable中选择*到StudentDB.dbo.AddressTable中


您无需使用脚本创建表,此脚本将创建表并将数据插入其中.
Run this query in your server by substituting Destination,Source databases and corresponding table name:


Select * into DestinationDatabase.dbo.Table From SourceDatabse.dbo.Table

For example,

Select * into StudentDB.dbo.AddressTable From EmployeeDB.dbo.AddressTable


You need not create the table using script,this one will create table and insert data into it.


您可以在"A"数据库中的所需表上单击鼠标右键,然后选择"SCRIPT TABLE"选项AS->创建至->新查询编辑器窗口,复制窗口中显示的脚本或查询,然后在"B"数据库中执行它.
You can right click on the required table in "A" database and select the option SCRIPT TABLE AS->CREATE TO->NEW QUERY EDITOR WINDOW , copy the script or query shown in the window and execute it inside the "B" database


Venkyanatraj是正确的.复制粘贴后,只需要再做一件事.在执行数据库之前,用脚本的第一行替换数据库的名称.即

用用户[b]代替[A]

它可以在SQL Server 2005中完美运行.
Venkyanatraj is right. Only you just have to do one more thing after copy paste. Substitute the name of the database on first line of script before executing it. i.e.,

Substitute Use [A] with User [b]

Its working perfectly in SQL Server 2005.


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

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