Question

I am using Microsoft SQL Server 2012 Express. The following code from MySQL gives me error when running query, can anyone guide me in how to correct it?

/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
create database  /*!32312 IF NOT EXISTS*/ `android_api`/*!40100 DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci */;
use `android_api` ;/** Selecting Database **/
DROP TABLE IF EXISTS `users`;
/** Creating Users Table **/
create table `users`(
   uid int(11) primary key auto_increment,
   unique_id varchar(23) not null unique,
   name varchar(50) not null,
   email varchar(100) not null unique,
   encrypted_password varchar(80) not null,
   salt varchar(10) not null,
   created_at datetime,
   updated_at datetime null
)ENGINE=InnoDB AUTO_INCREMENT=877888 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

DROP TABLE IF EXISTS `events`;
/** Creating Users Table **/
create table `events`(
   eid int(11) primary key auto_increment,
   unique_id varchar(23) not null unique,
   title varchar(50) not null,
   date varchar(50) not null,
   time varchar(50) not null,
   location varchar(100) not null,
   person varchar(20) not null,
   phone varchar(20) not null,
   budget varchar(20) not null,
   comments varchar(50) not null,
   resource varchar(150) not null,
   uuid varchar(23) not null,
   created_at datetime,
   updated_at datetime null
)ENGINE=InnoDB AUTO_INCREMENT=877888 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
Was it helpful?

Solution

create database android_api;
GO
use android_api;
GO
create table users(
   uid int identity(877888,1) primary key,
   unique_id varchar(23) not null unique,
   name varchar(50) not null,
   email varchar(100) not null unique,
   encrypted_password varchar(80) not null,
   salt varchar(10) not null,
   created_at datetime,
   updated_at datetime null
);
GO
create table events(
   eid int identity(877888,1) primary key,
   unique_id varchar(23) not null unique,
   title varchar(50) not null,
   date varchar(50) not null,
   time varchar(50) not null,
   location varchar(100) not null,
   person varchar(20) not null,
   phone varchar(20) not null,
   budget varchar(20) not null,
   comments varchar(50) not null,
   resource varchar(150) not null,
   uuid varchar(23) not null,
   created_at datetime,
   updated_at datetime null
);
GO

OTHER TIPS

MySQL and SQL Server are both relational databases that use SQL as the language to interact, but they are not 100% compatible.

The query you posted includes MySQL specific features such as the auto_increment primary key and InnoDB database engine.

If you're using SQL Server you can also download the SQL 2012 Management Studio Express here: http://www.microsoft.com/en-us/download/details.aspx?id=29062 This will give you a GUI for managing your SQL and creating your tables. Once you have those setup you can look at the SQL that's generated to see how the MS SQL looks.

I am assuming you are migrating a database from MySQL to SQL Server Express.

If you haven't tried yet, do a mysqldump of your db using the compatible parameter set to mssql.

mysqldump --compatible=mssql

This should provide you with the correct syntax to run on SQL Server Express.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top