Import sql syntax, Windows SQL Server and Apache Mysql - mysql

I have below sql export from Microsoft SQL Sever and I tried to import into Mysql running by Apache in osx. I got an Sql syntax error from line 1. I am new and I actually have never seen the sql using [ ] as quote fot string.
May I ask is the sql different from Sql Server in Windows and the
Mysql in Apache?
If I want to import below database into mysql, what should I check
and look at?
Thank you very much for your adverses!!
Best regards,
USE [boatexpress]
GO
/****** Object: Schema [boatexpress] Script Date: 07/22/2013 14:15:07 ******/
CREATE SCHEMA [boatexpress] AUTHORIZATION [boatexpress]
GO
/****** Object: Table [dbo].[waybill111] Script Date: 07/22/2013 14:15:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[waybill111](
[id] [int] IDENTITY(1,1) NOT NULL,
[slAAECode] [nvarchar](100) NULL,
[slProductName] [ntext] NULL,
[slRecName] [nvarchar](50) NULL,
[slRecMobi] [nvarchar](50) NULL,
[slRecAddress] [nvarchar](255) NULL,
[slZipCode] [nvarchar](50) NULL,
[slweight] [float] NULL,
[ktype] [nvarchar](50) NULL,
[worth] [nvarchar](150) NULL,
[adminid] [int] NULL,
[addtime] [date] NULL,
[insurance] [nvarchar](50) NULL,
CONSTRAINT [PK_waybill] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

The syntax from SQL to MySQL is different. If you want to create above table use this syntax.
Create the database
CREATE SCHEMA `boatexpress` ;
Create the table
CREATE TABLE boatexpress.waybill111 (
`id` int PRIMARY KEY AUTO_INCREMENT NOT NULL,
`slAAECode` nvarchar(100) NULL,
`slProductName` text NULL,
`slRecName` nvarchar(50) NULL,
`slRecMobi` nvarchar(50) NULL,
`slRecAddress` nvarchar (255) NULL,
`slZipCode` nvarchar(50) NULL,
`slweight` float NULL,
`ktype` nvarchar(50) NULL,
`worth` nvarchar(150) NULL,
`adminid` int NULL,
`addtime` date NULL,
`insurance` nvarchar(50) NULL);
Datatypes like ntext doesnt exists in MySQL. I just renamed it to TEXT. Also [] are not used to wrap columns but ` is. For datatypes you dont need to enclose them at all.
Is this what you are looking for?
Also, your SQL code is actually trying to use boatexpress before creating it.

Related

i am having some trouble with my sql file it shows these error while i tried to import ,please give me the solutions

I am having some trouble with my SQL file while I tried to import:
USE [db_events]
GO
/****** Object: Table [dbo].[Tbl_UserReg] Script Date: 04/09/2016 16:05:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Tbl_UserReg](
[UserId] [int] IDENTITY(1,1) NOT NULL,
[LogId] [int] NOT NULL,
[Name] [varchar](100) NOT NULL,
[Mob] [varchar](15) NOT NULL,
[Email] [varchar](100) NULL,
[CName] [varchar](100) NULL,
CONSTRAINT [PK_Tbl_UserReg] PRIMARY KEY CLUSTERED
(
[UserId] ASC
)WITH (PAD_I[...]
it shows these error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use
near 'U' at line 1
please use this code
CREATE TABLE Tbl_UserReg(
UserId INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
LogId INT NOT NULL,
NAME VARCHAR(100) NOT NULL,
Mob VARCHAR(15) NOT NULL,
Email VARCHAR(100) NULL,
CName VARCHAR(100) NULL
)
Thank you....

Using number of leaves taken field i need to calculate number of remaining leaves,loss of pay and leave taken in total

USE [ctsdev]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tbl_Leavetbl](
[Emp_id] [int] IDENTITY(1,1) NOT NULL,
[Month] [varchar](15) NULL,
[Year] [varchar](4) NULL,
[Rec_Name] [varchar](50) NULL,
[CompanyName] [varchar](30) NULL,
[Task] [varchar](20) NULL,
[NoOfDaysLeavTakn] [int] NOT NULL,
[NoOfAvailblLeav] [int] NULL,
[LossofPay] [int] NULL,
[LeaveTakndates] [varchar](200) NULL,
[TtlLeavTakn] [int] NULL,
CONSTRAINT [PK_tbl_Leavetbl] PRIMARY KEY CLUSTERED
(
[Emp_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
This is my table design.When the employee fills the number of leaves taken field ,with that value i need to find the remaining available leaves,like in an year only 12 leaves is permitted,and the total leaves he taken till to this month also have to display.
Is it possible through a procedure or any function ,could you please suggest some idea regarding this

MsSql Server , update query execution took too much time

I have a sql server db keeping our text document datas.
A specific table is keeping thousands of text paragraphs themself, This table suddenly started to respond so lately to update queries abnormally. Sometimes non-complicated basic update query takes 30 - 40 secs. to execute and asp.net application uses this table throws timeout exception.
Select queries last normal as before but update.
Why this happens and what should I do?
Server system is Windows 2008 R2 Standard and MsSql Server 2008 R2
Below's my table meta data.
CREATE TABLE [dbo].[MetinIcerikTablosuCari](
[ID] [int] IDENTITY(1,1) NOT NULL,
[MetinIsimID] [int] NOT NULL,
[MetinIsimID_Eski_1] [int] NULL,
[MetinIsimID_Eski_2] [int] NULL,
[MetinIsimID_Eski_3] [int] NULL,
[MetinIsimID_Eski_4] [int] NULL,
[MetinIsimID_Eski_5] [int] NULL,
[MetinIcindekilerID] [int] NOT NULL,
[SilmeTalebi] [bit] NULL,
[SiraNo] [int] NOT NULL,
[ParagrafMetin] [text] NOT NULL,
[RevizeParagraf] [text] NULL,
[RevizeVarMi] [bit] NULL,
[RevizasyonOnayi] [bit] NULL,
[RevizasyonTarihi] [datetime] NULL,
[RevizasyonSahibiID] [int] NULL,
[RevizasyonOnayTarihi] [datetime] NULL,
[RevizasyonOnaylayanID] [int] NULL,
[RevizasyonSonOnay] [bit] NULL,
[RevizeTuru] [int] NULL,
[ParagrafRevizeIslemJetonu] [nvarchar](50) NULL,
[BaglantiliOrtakRevizeSeriNo] [int] NULL,
[SonOnayTarihi] [datetime] NULL,
[SonOnaylayanID] [int] NULL,
[ParagrafMetin_Eski_1] [text] NULL,
[ParagrafMetin_Eski_2] [text] NULL,
[ParagrafMetin_Eski_3] [text] NULL,
[ParagrafMetin_Eski_4] [text] NULL,
[ParagrafMetin_Eski_5] [text] NULL,
[GirisTarihi] [nvarchar](50) NULL,
[YayinTarihi] [nvarchar](50) NULL,
[ParagrafNot] [nvarchar](max) NOT NULL,
[DipNotTag] [nvarchar](max) NOT NULL,
[MedyaURL] [nvarchar](100) NULL,
[MedyaUrlNot] [nvarchar](max) NOT NULL,
[VersiyonMetin] [int] NULL,
[EtkileyenMetinID] [int] NULL,
[tarih] [nvarchar](max) NULL,
[GuncellemeTarihi] [datetime] NULL,
[NotParagrafi] [bit] NULL,
[YeniParagraf] [bit] NULL,
[MedyaParagrafi] [bit] NULL,
[EslestirmeSilmeOnayID] [int] NULL,
[YargiOnBilgiSayfasi] [bit] NULL,
[BolumParagrafi] [bit] NULL,
[UstParagrafID] [int] NULL,
CONSTRAINT [PK_MetinIcerikTablosuCari] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_MetinIsimID] DEFAULT ((0)) FOR [MetinIsimID]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_MetinIcindekilerID] DEFAULT ((0)) FOR [MetinIcindekilerID]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_SiraNo] DEFAULT ((0)) FOR [SiraNo]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_ParagrafMetin] DEFAULT ('') FOR [ParagrafMetin]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_RevizeTuru] DEFAULT ((1)) FOR [RevizeTuru]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_ParagrafNot] DEFAULT ('') FOR [ParagrafNot]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_DipNotTag] DEFAULT ('') FOR [DipNotTag]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_MedyaUrlNot] DEFAULT ('') FOR [MedyaUrlNot]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_NotParagrafi] DEFAULT ((0)) FOR [NotParagrafi]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_YeniParagraf] DEFAULT ((0)) FOR [YeniParagraf]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_MedyaParagrafi] DEFAULT ((0)) FOR [MedyaParagrafi]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_EslestirmeSilmeOnayID] DEFAULT ((0)) FOR [EslestirmeSilmeOnayID]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_YargiOnBilgiSayfasi] DEFAULT ((0)) FOR [YargiOnBilgiSayfasi]
GO
ALTER TABLE [dbo].[MetinIcerikTablosuCari] ADD CONSTRAINT [DF_MetinIcerikTablosuCari_BolumParagrafi] DEFAULT ((0)) FOR [BolumParagrafi]
GO
I checked out and executed the update stats sp, but it seems the problem keeps going.
A simple update query like this: update MetinIcerikTablosuCari set ParagrafMetin = '<p>SPK Bültenleri - 2002/34: #media#93640#media#</p>' where ID = 35606 takes 20 - 30 secs or more.
I checked the CPU usage while the query executing, it suddenly picks to appr. 75 - 80%.
I could not determine if it's about lack of server memory or sql uses memory abnormally.
Below is my server hardware specifications:
Windows 2008 R2 Standard - Service Pack1
Processor: Intel Core i5-2400 CPU # 3.1 Ghz
RAM: 8GB
System Type: 64-bit
In addition, could this be kind of lack of updates for Windows Server or MsSql Server 2008 r2
As you haven't provided the execution plan and other necessary details, my assumption is that you might have indexes which are causing slow updates. Indexes helps running SELECT fast but slow down insert and update statements. List out all the indexes (Clustered & Non-Clustered) and then remove unnecessary indexes from your table.
Also, how often do you update statistics? If that is not recently done then run following SP
EXEC Sp_Updatestats;
If above two ways doesn't solve your problem then I recommend you to post table metadata and execution plan.

SQL statement with square brackets AUTO_INCREMENT error

My new VPN accepts only sql statements with square brackets hence I edited the traditional sql query to:
CREATE TABLE admin (
[id] int(11) NOT NULL AUTO_INCREMENT,
[name] varchar(128) NOT NULL,
[email] varchar(64) NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2;
But it shows this error:
Msg 102, Level 15, State 1, Line 1 Incorrect syntax near
'AUTO_INCREMENT'
Basically the server is windows azure and I am using Microsoft SQL server management studio to execute sql queries.
CREATE TABLE [dbo].[admin](
[id] [int](11) IDENTITY(1,1) NOT NULL,
[name] [varchar](128) NULL,
[email] [varchar](64) NULL,
CONSTRAINT [PK_admin] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
In sql server should be created auto increment to use IDENTITY not AUTO_INCREMENT. Like this
CREATE TABLE admin (
[id] int(11) IDENTITY(1,1) NOT NULL ,
[name] varchar(128) NOT NULL,
[email] varchar(64) NOT NULL,
PRIMARY KEY (id)
)
More detail to refer this link http://www.w3schools.com/sql/sql_create_table.asp
CREATE TABLE [dbo].[admin](
[ID] [int]IDENTITY(1,2) NOT FOR REPLICATION NOT NULL,
[name] [char](128) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[email] [varchar](64) NOT NULL,
PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

Converting SQL Server Create script to MySQL

I have the following SQL Server Create Script. Can anyone help me convert this to MySQL.
I'm not sure what the bit defining the Primary Key is doing.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE IF NOT EXISTS `webdb`.`UserSessions`(
UniqueID VARCHAR(50) NOT NULL,
UserID VARCHAR(255) NOT NULL,
TokenExpires DATETIME NOT NULL,
LastSeen DATETIME NOT NULL,
LoggedOut bit NOT NULL,
CONSTRAINT [PK_EndedSessions] PRIMARY KEY CLUSTERED
(
UniqueID ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE TABLE IF NOT EXISTS `webdb`.`UserSessions`
(
UniqueID VARCHAR(50) NOT NULL PRIMARY KEY,
UserID VARCHAR(255) NOT NULL,
TokenExpires DATETIME NOT NULL,
LastSeen DATETIME NOT NULL,
LoggedOut bit NOT NULL
);