将MySQL * .sql脚本(语句)转换为MS SQL SERVER * .sql脚本(语句)

时间:2014-01-20 01:29:03

标签: mysql sql sql-server

如何将MySQL * .sql脚本(语句)转换为MS SQL SERVER * .sql脚本(语句)?

例如,这是MySQL sql语句:

DROP TABLE IF EXISTS `qs_ad_category`;
CREATE TABLE `qs_ad_category` (
  `id` smallint(5) unsigned NOT NULL auto_increment,
  `alias` varchar(100) NOT NULL,
  `type_id` int(10) unsigned NOT NULL,
  `categoryname` varchar(100) NOT NULL,
  `admin_set` tinyint(3) unsigned NOT NULL default '0',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM ;

DROP TABLE IF EXISTS `qs_admin`;
CREATE TABLE `qs_admin` (
  `admin_id` smallint(5) unsigned NOT NULL auto_increment,
  `admin_name` varchar(40) NOT NULL,
  `email` varchar(40) NOT NULL,
  `pwd` varchar(32) NOT NULL,
  `pwd_hash` varchar(30) NOT NULL,
  `purview` TEXT  NOT NULL,
  `rank` varchar(32) NOT NULL,
  `add_time` int(10) NOT NULL,
  `last_login_time` int(10) NOT NULL,
  `last_login_ip` varchar(15) NOT NULL,
  PRIMARY KEY  (`admin_id`)
) TYPE=MyISAM ;

当然我无法在MS SQL SERVER2012中执行此脚本,因为某些语法不同。有没有快速的转换方式?或者最好的方法是手动重写MS SQL版本吗?

1 个答案:

答案 0 :(得分:0)

试试这个:

use master;
go
if db_id('name_of_the_database')is not null
begin
    drop database name_of_the_database;
end

go
create database name_of_the_database;
go
use name_of_the_database;
go


if object_id ('qs_ad_category')is not null
begin 
    drop table qs_ad_category;
end

create table qs_ad_category
(
id smallint check (id between 1 and 5) NOT NULL IDENTITY(1, 1) primary key,
alias varchar(100) NOT NULL,
type_id int check (type_id between 1 and 10) NOT NULL,
categoryname varchar(100) NOT NULL,
admin_set tinyint  check(admin_set between 1 and 3) NOT NULL default '0'
);
go