如何将 mySql SQL 脚本转换为 MS SQL 脚本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7820626/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I convert mySql SQL script to MS SQL one?
提问by Andrew Florko
I have to migrate customer MySql database schema/data to MS SQL SERVER 2008. Finally I've received 70 Mb SQL file with mySQL dialect that is incompatible with MSSQL.
我必须将客户 MySql 数据库架构/数据迁移到 MS SQL SERVER 2008。最后,我收到了 70 Mb SQL 文件,其中包含与 MSSQL 不兼容的 mySQL 方言。
DROP TABLE IF EXISTS `kladr`;
CREATE TABLE `kladr` (
`id` int(11) NOT NULL DEFAULT '0',
`idp` int(11) DEFAULT NULL,
...
It took a week of negotiations to receive such a file so I'm afraid to ask mySQL administrators to send me MS SQL SERVER compatible sql. Is there a way to convert mySQL dialect to MSSQL SERVER dialect automatically ?
收到这样的文件花了一个星期的谈判,所以我不敢要求 mySQL 管理员给我发送与 MS SQL SERVER 兼容的 sql。有没有办法将 mySQL 方言自动转换为 MSSQL SERVER 方言?
回答by Jerold Joel
SQLines provides tools and services to help you transfer data, convert database schema (DDL), views, stored procedures and functions, triggers, queries, embedded SQL statements and SQL scripts from MySQL to Microsoft SQL Server.
SQLines 提供的工具和服务可帮助您将数据、数据库架构 (DDL)、视图、存储过程和函数、触发器、查询、嵌入式 SQL 语句和 SQL 脚本从 MySQL 传输到 Microsoft SQL Server。
回答by Nanne
The easiest method would be to obtain a converter. There are multiple options available, but It might be difficult to find a good one: a lot of spammy options are available, all costing money ofcourse.
最简单的方法是获得转换器。有多种选项可用,但可能很难找到一个好的选项:有很多垃圾邮件选项可用,当然所有选项都需要花钱。
Microsoft has a manual online for migration: http://technet.microsoft.com/en-us/library/cc966396.aspx
Microsoft 有在线迁移手册:http: //technet.microsoft.com/en-us/library/cc966396.aspx
You'll be needing some mysql tools and some mssql tools, stated on above link.
您将需要上面链接中所述的一些 mysql 工具和一些 mssql 工具。
Adding a short exerpt:
If you check out the part called 'Using Data Loading'. The export file you allready have is probably fine, so you can go and skip 'Generating mysqldump Data Extract Scripts'.
添加一个简短的摘录:
如果您查看名为“使用数据加载”的部分。您已经拥有的导出文件可能没问题,因此您可以跳过“生成 mysqldump 数据提取脚本”。
Now the part you need:
现在你需要的部分:
Using the extracted scripts with SQL Query Analyzer
Generated scripts can now be used to create database objects and insert data. The preferred method to construct a database schema from MySQL scripts is to use the SQL Query Analyzer tool that is included with SQL Server 2000.
You can run SQL Query Analyzer directly from the Start menu, or from inside SQL Server Enterprise Manager. You can also run SQL Query Analyzer from the command prompt by executing the isqlw utility.
In order for the script to correctly execute there is some additional work required, which involves certain changes with the SQL dialect. Also, remember to walk through the SQL script and change the data types to SQL Server compatible types. The diagram below shows an imported script from mysqldump, it is important to note that the dump is an ASCII script file.
将提取的脚本与 SQL 查询分析器
一起使用 生成的脚本现在可用于创建数据库对象和插入数据。从 MySQL 脚本构建数据库架构的首选方法是使用 SQL Server 2000 附带的 SQL 查询分析器工具。
您可以直接从“开始”菜单或从 SQL Server 企业管理器内部运行 SQL 查询分析器。您还可以通过执行 isqlw 实用程序从命令提示符运行 SQL 查询分析器。
为了使脚本正确执行,需要一些额外的工作,其中涉及 SQL 方言的某些更改。此外,请记住遍历 SQL 脚本并将数据类型更改为 SQL Server 兼容类型。下图显示了从 mysqldump 导入的脚本,重要的是要注意转储是一个 ASCII 脚本文件。
回答by Sparky
There are a few ways to test whether a table exists in SQL. Here is one approach.
有几种方法可以在 SQL 中测试表是否存在。这是一种方法。
if object_id('<table>','U') is not null drop <table>
So you would need to convert all of the
所以你需要转换所有的
DROP TABLE IF EXISTS `kladr`;
to that syntax. Note that there are other approaches to see if a table exists as well.
到那个语法。请注意,还有其他方法可以查看表是否存在。
Also, MS-SQL doesn't use the ` (backtick) character, so you would need to get rid of all of them. However, some of the field/table names currently surrounded by backticks might be reserved words, in which case, you need to delimit those fields/tables with [fld_name] with brackets.
此外,MS-SQL 不使用 `(反引号)字符,因此您需要删除所有这些字符。但是,当前被反引号包围的某些字段/表名称可能是保留字,在这种情况下,您需要使用带括号的 [fld_name] 分隔这些字段/表。
You might also run into some differences in the create table syntax, also the basic syntax is similar. The examples above would work in MS-SQL...
您可能还会遇到 create table 语法的一些差异,基本语法也相似。上面的例子可以在 MS-SQL 中工作......
You can do it with script editing, but I would strongly suggest using the link suggested by Nanne above. Good luck
您可以通过脚本编辑来完成,但我强烈建议使用上面 Nanne 建议的链接。祝你好运
回答by Jan
You could (re)create the MySQL database from the MySQL scripts you received and use a database conversion tool. I have used FullConvertin the past and works excellent. Supports many databases and is very fast!
您可以(重新)从您收到的 MySQL 脚本创建 MySQL 数据库并使用数据库转换工具。我过去使用过FullConvert并且效果很好。支持多种数据库,速度非常快!