MSSQL存储过程转为MySQL的步骤

首先,跟原来迁移数据表一样,第一步, 在MS SQLServer中导出所有SP的脚本,copy到SQL Analyser中, 接着把所有MS SQLServer特征并且不需要的脚本,比如GO,等,全部删除掉!

第二步, 把存储过程体格式修改成MySQL格式, 主要是参数(MySQL的参数是不能让@开头的), 过程体(包含小括号, 丢掉as, 新的方法体要包含begin,end),这些每个都一样,所以批量进行一,二步都很快, 现在第三步主要就是要把知道的mysql和MS SQL不同的语法进行替换修改, 比如if 条件语句,getdate()函数, top 换为limit, update语句把from后的放到update后面等.


 


Select top 10 bid from books

Select bid from books limit 0,10

select bsid=@@IDENTITY

select bsid=LAST_INSERT_ID()

If xxx

Begin

--------

End

Else if xxx

Begin

end

If xxx then

--------

else

if xxx then

-----

end if;

end if;

exec sp a,b,c

Call sp(a,b,c)

getdate()

now()

day(xx)

dayofmonth(xx)

Create procedure xxx @a int @b varchar(100)

As

 

Create procedure xxx (a int,b varchar(100))

Begin

End

动态sql语句Exec(‘xxxx’)

 

在任何位置均可声明

Sp内部必需在一开始就声明

不需要

除控制语句,句子后面必需加分号

Cast(a as xxx)

如果是转为字符串,最好用CONCAT()

with (nolock)

没找到对应的,

Create proc

没有proc缩写,必需改为create procedure

跨数据库访问[xx].[dbo].[aaa]

省略dbo: xx.aaa

update bookvotes set a.votes=a.votes+(select sum(starVotes) from bookreviews where bid=a.bid) from bookvotes a,bookreviews b

where a.status=0 and a.bid=b.bid and b.status=1;

update bookvotes a,bookreviews b set a.votes=a.votes+(select sum(starVotes) from bookreviews where bid=a.bid)

where a.status=0 and a.bid=b.bid and b.status=1;

 

你可能感兴趣的:(MSSQL存储过程转为MySQL的步骤)