首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

MYsql怎么像SqlServer一样在查询分析器中执行多行语句

2012-06-08 
MYsql如何像SqlServer一样在查询分析器中执行多行语句SQL codeuse pubsdeclare @fid int declare @milesto

MYsql如何像SqlServer一样在查询分析器中执行多行语句

SQL code
use pubsdeclare @fid int declare @milestone intdeclare @count intdeclare @val intset @fid = 1set @milestone = 1truncate table milestone--得到总的milestone数select  @count = count(1) / 10000from    threadwhere   fid = @fid--第一个milestoneselect top 1        @val = lastpostfrom    thread with ( nolock )where   fid = @fid        and lastpost not in ( select top 10000                                        lastpost                              from      thread with ( nolock )                              where     fid = @fid                              order by  lastpost desc )order by lastpost descinsert  into milestone        ( fid, milestone, lastpostdesc )values  ( @fid, @milestone, @val )set @milestone = @milestone + 1while ( @milestone <= @count )     begin            select top 1                @val = lastpost        from    thread with ( nolock )        where   fid = @fid                and lastpost < @val                and lastpost not in ( select top 10000                                                lastpost                                      from      thread with ( nolock )                                      where     fid = @fid                                                and lastpost < @val                                      order by  lastpost desc )        order by lastpost desc                insert  into milestone                ( fid, milestone, lastpostdesc )        values  ( @fid, @milestone, @val )            set @milestone = @milestone + 1    end


在SqlServer中我们常常合并多行语句然后直接执行,但是在mysql中如何执行以上语句呢?
我是想直接在代码里边执行,例如:
mySqlHelper.ExecuteQuery("这里是上面的sql语句");

[解决办法]
MYSQL中无法实现这种过程式语句,只能在存储过程中使用。
如果是一般的多条SQL语句则可以通过分号来分隔即
select now(); select 1+1 ;
[解决办法]
mysql是不能执行多条语句的。每条语句要分号隔开的。
mysql要实现此功能必须在存储过程中实现的。

热点排行