1

I have a MSSQL queries file(.sql), now I need to convert it to MYSQL queries. Please help me. The script like this:

CREATE TABLE [dbo].[Artist](
    [ArtistId] [int] IDENTITY(1,1) NOT NULL,
    [Name] [nvarchar](120) NULL,
PRIMARY KEY CLUSTERED 

(
    [ArtistId] ASC

)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

) ON [PRIMARY]
1
  • That looks like DDL, not a Query? Commented Nov 27, 2012 at 12:06

1 Answer 1

3

If you want to convert the DDL by hand, then you can do this by building up rules on a case by case basis, e.g. as follows:

  • [] need to be replaced with backticks
  • IDENTITY(1,1) can be replaced with AUTO_INCREMENT
  • Most of the ANSI options and Device settings can be ignored (these seem to be present only because the table has been rescripted)
  • w.r.t. dbo, MySQL doesn't implement schemas in the same way as SQL Server - you will either need to separate schemas into databases, or drop the schema, or mangle the schema name into the tablename (e.g. as a Prefix)

This will leave you with something like the following:

CREATE TABLE `Artist`(
    `ArtistId` int NOT NULL AUTO_INCREMENT,
    `Name` nvarchar(120) NULL,
    PRIMARY KEY CLUSTERED 
    (
       `ArtistId` ASC
    )
);

Fiddle here

However, it is usually much easier to do this migration with a migration tool - search for the section on How to Transition from SQL Server to MySQL

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.