使用存储过程将数据从MS Sql导入MySQL

时间:2021-05-02 23:53:29

I am importing data into an application that uses MySQL. The data is coming from MS SQL. Because the table names change every month in the MS SQL db we are using a stored procedure to concatenate the table name in addition to getting data from other tables.

我正在将数据导入到使用MySQL的应用程序中。数据来自MS SQL。因为表名在MS SQL数据库中每个月都在变化,所以除了从其他表中获取数据之外,我们还使用存储过程来连接表名。

The problem is that it seems we are losing the PK identifier on the MS SQL side so my MySQL database won't take the data. Should we be using a view instead? Is there a way to retain the PK identity in a stored procedure. Thanks.

问题是我们似乎正在丢失MS SQL端的PK标识符,因此我的MySQL数据库不会获取数据。我们应该使用视图吗?有没有办法在存储过程中保留PK身份。谢谢。

Here's a better explanation of my problem: 1. Host database table name change each month (YYYYMMtablename) 2. Need to select columns from two tables 3. The foreign DB (MySQL) needs a query like SELECT a,b,c,d,from tablename 4. I am not able to alter the way my application works, although I can make changes to the database.

这里有一个更好的解释我的问题:1。主机数据库表名每月更改(YYYYMMtablename)2。需要从两个表中选择列3.外国数据库(MySQL)需要查询如SELECT a,b,c,d,来自tablename 4.虽然我可以对数据库进行更改,但我无法改变应用程序的工作方式。

1 个解决方案

#1


0  

You can specify the identity value in an insert statement on both SQL Server and MySQL.

您可以在SQL Server和MySQL上的insert语句中指定标识值。

MySQL allows you inserting identity values explicitly, so you actually do not need IDENTITY_INSERT option, or in other words it is always set in MySQL. MySQL forums

MySQL允许您显式插入标识值,因此您实际上不需要IDENTITY_INSERT选项,换句话说,它总是在MySQL中设置。 MySQL论坛

For MS SQL Server, please read the SET IDENTITY_INSERT (Transact-SQL) documentation.

对于MS SQL Server,请阅读SET IDENTITY_INSERT(Transact-SQL)文档。

#1


0  

You can specify the identity value in an insert statement on both SQL Server and MySQL.

您可以在SQL Server和MySQL上的insert语句中指定标识值。

MySQL allows you inserting identity values explicitly, so you actually do not need IDENTITY_INSERT option, or in other words it is always set in MySQL. MySQL forums

MySQL允许您显式插入标识值,因此您实际上不需要IDENTITY_INSERT选项,换句话说,它总是在MySQL中设置。 MySQL论坛

For MS SQL Server, please read the SET IDENTITY_INSERT (Transact-SQL) documentation.

对于MS SQL Server,请阅读SET IDENTITY_INSERT(Transact-SQL)文档。