MySQL社区

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 7322|回复: 1

[迁移&移植] MSSQL迁移MySQL[存储过程的迁移]

[复制链接]
发表于 2010-10-20 17:14:56 | 显示全部楼层 |阅读模式
首先,跟原来迁移数据表一样,第一步, 在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;

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|申请友链|小黑屋|Archiver|手机版|MySQL社区 ( 京ICP备07012489号   
联系人:周生; 联系电话:13911732319

GMT+8, 2024-3-28 17:34 , Processed in 0.065951 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表