USE 数据库名称1;
DROP PROCEDURE IF EXISTS 数据库名称1.存储过程名称;
delimiter $$
CREATE PROCEDURE 数据库名称1.存储过程名称(in v_count bigint,in v_count2 bigint)
BEGIN
set @vCount1=v_count;
set @vCount2=v_count2;

set @i=1;
set @vintervala=10000;
set @vintervalb=10000;
while(@i<=@vCount1)
do
#随机获取一个版块ID
select fid into @vfid from tps_forum_forum where fup<>0 and `type`='forum' and `status`=1 order by rand() limit 1;

#获取pid
select ifnull(max(pid)+1,1) into @vpid from tps_forum_post;

#获取tid
select ifnull(max(tid)+1,1) into @vtid from tps_forum_post;

#获取发帖的storeid username
select m.uid,m.username into @vuida,@vusernamea from tps_common_member m where m.uid>4 and m.`status`=0 order by rand() limit 1,1;

set @vintervala=@vintervala+@i;
set @vintervalb=@vintervalb+@i*100;

set @vtitlea=concat('发帖标题',floor(1+RAND()*10000000));
set @vpostdate=unix_timestamp(DATE_FORMAT(LOCALTIME()+@vintervala,'%Y-%m-%d %H:%i:%S'));

set @vip='192.168.1.1';
set @vmessagea=concat('发帖内容',floor(1+RAND()*10000000),'\r\n');
set @vporta=floor(10000+RAND()*55535);

#set @vportb=floor(10000+RAND()*55535);
set @vmessageb=concat('回复的第',@vtid,'个帖子的内容');

#3新增发送帖子的信息
INSERT INTO `tps_forum_post` (`pid`, `fid`, `tid`, `first`, `author`, `authorid`, `subject`, `dateline`, `message`, `useip`, `port`,
`invisible`, `anonymous`, `usesig`, `htmlon`, `bbcodeoff`, `smileyoff`, `parseurloff`, `attachment`, `rate`, `ratetimes`, `status`, `tags`, `comment`, `replycredit`, `position`)
VALUES (@vpid, @vfid, @vtid, 1, @vusernamea, @vuida, @vtitlea,@vpostdate,@vmessagea, @vip, @vporta, 0, 0, 1, 0, -1, -1, 0, 0, 0, 0, 0, '', 0, 0, 1);

#最新主题信息表
INSERT INTO `tps_forum_newthread` (`tid`, `fid`, `dateline`) VALUES (@vtid,@vfid, @vpostdate);

#分表协调信息表
insert into tps_forum_post_tableid values();

#假设1个帖子有50000个回复
set @j=1;
while(@j<=@vCount2)
do
#获取回帖的storeid username
select m.uid,m.username into @vuidb,@vusernameb from tps_common_member m where m.uid>4 and m.`status`=0 order by rand() limit 1000,1;

#获取pid
select ifnull(max(pid)+1,1) into @vpid from tps_forum_post;

set @vreplaydate=unix_timestamp(DATE_FORMAT(LOCALTIME()+@vintervalb,'%Y-%m-%d %H:%i:%S'));

set @vposition=@j+1;

#2分表协调表
insert into tps_forum_post_tableid values();

#3新增回复帖子的信息
INSERT INTO `tps_forum_post` (`pid`, `fid`, `tid`, `first`, `author`, `authorid`, `subject`, `dateline`, `message`, `useip`, `port`,
`invisible`, `anonymous`, `usesig`, `htmlon`, `bbcodeoff`, `smileyoff`, `parseurloff`, `attachment`, `rate`, `ratetimes`, `status`, `tags`, `comment`, `replycredit`, `position`)
VALUES (@vpid, @vfid, @vtid, 0, @vusernameb, @vuidb, '', @vreplaydate, @vmessageb, @vip, @vporta, 0, 0, 1, 0, -1, -1, 0, 0, 0, 0, 0, '0', 0, 0, @vposition);

#主题参与者记录表,第1个回复的帖子信息
INSERT INTO `tps_forum_threadpartake` (`tid`, `uid`, `dateline`)
select tid,authorid,dateline
from tps_forum_post where fid=@vfid and tid=@vtid and first=0 and position=2;

#主题参与者记录表,第@vCount2+1个回复的帖子信息
INSERT INTO `tps_forum_threadpartake` (`tid`, `uid`, `dateline`)
select tid,authorid,dateline
from tps_forum_post where fid=@vfid and tid=@vtid and first=0 and position=@vCount2+1;

COMMIT;

set @j=@j+1;
end while;

#获取position
select max(position) into @vposition from tps_forum_post where first=0 and tid=@vtid;
select count(0) into @vreplay from tps_forum_post where first=0 and tid=@vtid;
select max(dateline) into @vreplaydate from tps_forum_post where first=0 and tid=@vtid;

#1论坛主题信息表
INSERT INTO `tps_forum_thread` (`tid`, `fid`, `posttableid`, `typeid`, `sortid`, `readperm`, `price`, `author`, `authorid`, `subject`, `dateline`, `lastpost`,
`lastposter`, `views`, `replies`, `displayorder`, `highlight`, `digest`, `rate`, `special`, `attachment`, `moderated`, `closed`, `stickreply`, `recommends`,
`recommend_add`, `recommend_sub`, `heats`, `status`, `isgroup`, `favtimes`, `sharetimes`, `stamp`, `icon`, `pushedaid`, `cover`, `replycredit`, `relatebytag`,
`maxposition`, `bgcolor`, `comments`, `hidden`)
VALUES (@vtid,@vfid, 0, 0, 0, 0, 0, @vusernamea, @vuida, @vtitlea, @vpostdate, @vreplaydate,@vusernamea, floor(1000+rand()*10000), @vreplay, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, floor(0+rand()*2), 32, 0, 0, 0, -1, -1, 0, 0, 0, '0', @vposition, '', 0, 0);

#获取版块内主题数量
select count(0) into @vthreadCount from tps_forum_thread where fid=@vfid;

#获取版块内发帖子数量
select count(0) into @vpostCount from tps_forum_post where first=1 and fid=@vfid;

#获取今日发帖数量
select count(0) into @vtodayposts from tps_forum_post where first=1 and fid=@vfid
and dateline>=unix_timestamp(date_format(localtime(),'%Y-%m-%d')) and
dateline<=unix_timestamp(DATE_ADD(date_format(localtime(),'%Y-%m-%d'),INTERVAL 24*60*60-1 SECOND));

#获取发帖综合信息
select fp.pid,fp.message,fp.dateline,fp.author into @vpid,@vmessage,@vdateline,@vauthor
from tps_forum_post fp where first=1 and fid=@vfid order by dateline desc limit 1;

#更新版块表中 主题 帖子 今日发帖数据 及发帖综合信息
update tps_forum_forum ff set ff.threads=@vthreadCount,ff.posts=@vpostCount,ff.todayposts=@vtodayposts,
ff.lastpost=concat(@vpid,@vmessage,@vdateline,@vauthor) where ff.fid=@vfid;

COMMIT;

set @i=@i+1;

END WHILE;
end $$
delimiter ;

call 数据库名称1.存储过程名称(3,10);

MySQL存储过程(批量生成论坛中发帖、回帖、主题等数据)的更多相关文章

  1. 通过存储过程批量生成spool语句

    过存储过程批量生成spool语句 CREATE OR REPLACE PROCEDURE pro_yx_full_txt IS export_handle UTL_FILE.file_type; v_ ...

  2. MySql存储过程批量删除多个数据库中同名表中的指定字段

    1. 创建存储过程batchDeleteField:删除所有名称为"MyDB_"开头的数据库中的指定字段 -- ---------------------------- -- Pr ...

  3. MySql存储过程批量给多个数据库中的同名表添加字段

    1 创建存储过程 batchAddField:给所有"MyDB_"开头的数据库添加新字段 -- ---------------------------- -- Procedure ...

  4. mysql存储过程批量向表插入数据

    业务需要,往某个表中批量插入数据,使用存储过程插入 首先,要建立一张mysql表,表明为phone_number, 三个字段,id 自增,number 就是要插入的表格,is_used 表示十分已经使 ...

  5. 原!mysql存储过程 批量导入数据

    mysql需要导入某前缀例如12345为前缀的,后缀扩展2位 即00-99. 利用存储过程插入数据. DROP PROCEDURE IF EXISTS insert_popsms_code;DELIM ...

  6. mysql 存储过程批量删除重复数据

    表结构: LOAD DATA INFILE '/usr/local/phone_imsi_12' replace INTO TABLE tbl_imsi2number_new FIELDS TERMI ...

  7. Mysql 存储过程批量建表

    CREATE DEFINER=`root`@`%` PROCEDURE `createTables`() begin declare i int; declare suffix varchar(20) ...

  8. mysql存储过程批量插入数据

    DROP TABLE IF EXISTS TeachersInfo; CREATE TABLE TeachersInfo ( id INT NOT NULL AUTO_INCREMENT, teach ...

  9. php 之根据mysql字段 批量生成 array 数组

    ci框架 验证字段 需要 生成类似为: array('field' => 'admin_id','label' => '账号ID','rules' => 'integer'),    ...

随机推荐

  1. 苹果app(iOS app)的URL schemes

    最近折腾iOS快捷启动应用或应用内的某个动作的神器launch center pro (LCP),发现很多国产app并没有被LCP官方收录,所以不得不想办法找到app的url schemes. 下面是 ...

  2. Redis配置主从架构,实现读写分离

    Redis的主从架构,能帮助我们实现读多,写少的情况,下面配置Redis架构,很简单. 准备环境 vmware + rhel-server-7.0(101,102,103)+redis-3.2.0 1 ...

  3. 九、myeclipse开发背景保护色设置

    window->preferences->Editors->Text Editors->Background color 背景颜色向你推荐: 色调:85.饱和度:1 2 3.亮 ...

  4. Summit Online Judge

    题意: 询问将取值在 $[L,R]$ 的若干个整数相加,可以得到 $[x,y]$ 区间内多少个数字. 解法: 只需要考虑求 $[L,R]$ 的数字能凑出 $[1,n]$ 的多少个数字,即可得出答案. ...

  5. C++类静态变量的一种使用特例

    不同进程里的数据默认情况下是互不影响的. 静态变量是属于类本身的,它的所有实例可以共享这个静态变量,但是有个先天条件就是在同一个进程的情况下!!

  6. 将字符串中的字符按Z字形排列,按行输出

    示例1: Input: s = "PAYPALISHIRING", numRows = 3 Output: "PAHNAPLSIIGYIR" 示例2: Pyth ...

  7. 算法学习--Day8

    今天重拾算法复习. 今天学习了两个类型的算法——并查集与最小生成树(MST) 简单记录一下并查集的大致内容. 一.并查集的内容大致作用为查找当前图中的点有几个集合. 该算法起到查询分组的情况.通过给定 ...

  8. [Xcode 实际操作]九、实用进阶-(7)使用Xcode的版本管理功能(SCM)

    目录:[Swift]Xcode实际操作 本文将演示系统的版本控制功能. 软件配置管理(SCM):Software configuration management 是指通过执行版本控制.变更控制的规程 ...

  9. ZK的选举算法

    一.前言 前面学习了Zookeeper服务端的相关细节,其中对于集群启动而言,很重要的一部分就是Leader选举,接着就开始深入学习Leader选举. 二.Leader选举 2.1 Leader选举概 ...

  10. BZOJ3224普通平衡树

    洛谷题面链接 很早就过了,太久没打了,原本是在noip前用来练emacs的手感的. noip炸了,就滚回来更博客了(安排的计数任务刷不动,学不会容斥,打发时间...) 众所周知,splay是个好算法, ...