Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Converting My SQL to MS SQL

Posted on 2014-03-30
6
Medium Priority
?
311 Views
Last Modified: 2014-03-30
I need help to ensure that I had the syntax correct when converting MS SQL from My SQL when trying to create a table. For some reason I am having problems getting the syntax correct. See attach file.
SQL
0
Comment
Question by:WDJ98338
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 39964608
Which one is correct and working?
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39964613
The mysql one works. Just tested it in phpmyadmin.
0
 

Author Comment

by:WDJ98338
ID: 39964614
The one on the top is MS SQL which I am trying to get to work and the one on the bottom is my SQL.

I am trying to convert the MySQL into MS SQL.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:WDJ98338
ID: 39964618
Yes I know the my SQL works I am trying to convert the My SQL into MS SQL to create a table and in MS SQL.
0
 
LVL 49

Accepted Solution

by:
PortletPaul earned 2000 total points
ID: 39964627
SQL Server does not support the enum data type, too many square brackets, there is one too many comma at the end & other comments below
CREATE TABLE [dbo].[Country]
      (
            [Code] char(3) NOT NULL            /* why use char instead of varchar or nvarchar ?? */
          , [Name] char(52) NOT NULL
          , [Continent] [varchar](30) NOT NULL /* enum is not supported */
          , [Region] [char](26) NOT NULL
          , [SurfaceArea] decimal(10, 2)       /* use decimal */
          , [IndepYear] smallint
          , [Population] int NOT NULL
          , [LifeExpectancy] decimal(3, 1)
          , [GNP] decimal(10, 2)
          , [GNPOld] decimal(10, 2)
          , [LocalName] char(45) NOT NULL
          , [GovernmentForm] char(45) NOT NULL
          , [HeadOfState] char(60)
          , [Capital] int
          , [Code2] char(2) NOT NULL
      )
;

Open in new window

For the enum one approach is to create a lookup table for those values (as the primary key of that table) then create a foreign key in this table to the lookup table.

or you can do something like this:
CREATE TABLE [dbo].[Country]
      (
            [Code] char(3) NOT NULL            /* why use char instead of varchar or nvarchar ?? */
          , [Name] char(52) NOT NULL
          , [Continent] [varchar](30) NOT NULL CHECK (Continent IN ('a', 'b', 'c')) /* enum is not supported */
          , [Region] [char](26) NOT NULL
          , [SurfaceArea] decimal(10, 2)       /* use decimal */
          , [IndepYear] smallint
          , [Population] int NOT NULL
          , [LifeExpectancy] decimal(3, 1)
          , [GNP] decimal(10, 2)
          , [GNPOld] decimal(10, 2)
          , [LocalName] char(45) NOT NULL
          , [GovernmentForm] char(45) NOT NULL
          , [HeadOfState] char(60)
          , [Capital] int
          , [Code2] char(2) NOT NULL
      )
;

Open in new window

ps: there's no need to add sql as a file, just use a code block
0
 

Author Closing Comment

by:WDJ98338
ID: 39964636
Thank you very much....
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question