如何使用将表复制到另一个数据库表 [英] How to use copy a table to another database table
本文介绍了如何使用将表复制到另一个数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我想使用
Select * into DestinationDB.dbo.tableName from SourceDB.dbo.SourceTable
语句:将表格模式和数据从一个数据库复制到SQL Server中的另一个数据库
问题是,我想使用表名的参数而不是像这样的语句中给出它:
statement in SQL according to this article: Copy Table Schema and Data From One Database to Another Database in SQL Server
The thing is, i want to use a parameter for a table name instead of giving it from the statement like this:
SELECT * INTO DestinationDatabase.dbo."@copiedTableName" FROM SourceDatabase.dbo."@copiedTableName"
但显然我不能为SourceDatabase使用参数化表名。使用表名参数的任何其他方法吗?在此先感谢。
But apparently i can't use a parameterized table name for SourceDatabase. Any other ways to do it with table name parameter? Thanks in advance.
推荐答案
看看MSSQL的程序 sp_executesql 。
sp_executesql允许你创建一个包含要运行的SQL语句的动态字符串,所以你应该能够合并你的动态表名进入SQL语句。
希望它有所帮助。
Have a look at MSSQL's procedure sp_executesql.
sp_executesql allows you create a dynamic string containing the SQL statement to run, so you should be able to incorporate you dynamic table name into the SQL statement.
Hope it helps.
我不知道表副本,
但您可以从第一个读取数据并将读取的数据插入第二个表格。
读一个{
将数据放入数组中。
}
将数据插入第二个表格
用于循环。
i dont know about table copy,
but you can read data from first one and insert the read data to the second table.
read one{
put data in an array.
}
insert data to the second table
use for loop.
这篇关于如何使用将表复制到另一个数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文