mysql-order by原理
阿新 • • 發佈:2021-12-10
測試資料建立
1.新建表
CREATE TABLE `user_info` ( `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主鍵ID', `city` varchar(16) NOT NULL COMMENT '城市', `name` varchar(16) NOT NULL COMMENT '姓名', `age` int(11) NOT NULL COMMENT '年齡', `addr` varchar(128) DEFAULT NULL COMMENT '地址', PRIMARY KEY (`id`), KEY `city` (`city`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8
2.刷測試資料儲存過程新建
-- 宣告儲存過程 DELIMITER // CREATE PROCEDURE callback() begin declare num int; set num = 1; LOOP_LABLE : loop INSERT INTO user_info(id,city,`name`,age,addr) VALUES(num,CONCAT("成都", num),CONCAT("小李", num),CONCAT(num),CONCAT("高新區",num)); set num =num + 1; if num >= 100000 then leave LOOP_LABLE; end if; end loop; end;
3.執行儲存過程
CALL callback();
4.刪除儲存過程
drop procedure IF EXISTS callback;
5.再重新建立儲存過程並執行
CREATE PROCEDURE callback() begin declare num int; set num = 100000; LOOP_LABLE : loop INSERT INTO user_info(id,city,`name`,age,addr)VALUES(num,"廣州",CONCAT("小李", num),CONCAT(num),CONCAT("高新區",num)); set num = num + 1; if num >= 200000 then leave LOOP_LABLE; end if; end loop; end;