SHARE
TWEET

Untitled

a guest Nov 12th, 2015 137 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE TABLE `users` (
  2.   `id` INT(11) NOT NULL AUTO_INCREMENT,
  3.   `age` INT(11) NOT NULL DEFAULT '0',
  4.   `num` INT(11) NOT NULL DEFAULT '0',
  5.   PRIMARY KEY (`id`),
  6.   KEY `age` (`age`),
  7.   KEY `num` (`num`)
  8. ) ENGINE=InnoDB AUTO_INCREMENT=11112 DEFAULT CHARSET=utf8
  9.  
  10.  
  11. DELIMITER $$
  12. DROP PROCEDURE IF EXISTS InsertRand;
  13. CREATE PROCEDURE InsertRand(IN NumRows INT, IN MinVal INT, IN MaxVal INT)
  14.     BEGIN
  15.         DECLARE i INT;
  16.         SET i = 1;
  17.         START TRANSACTION;
  18.         WHILE i <= NumRows DO
  19.             INSERT INTO users VALUES (i, MinVal + CEIL(RAND() * (MaxVal - MinVal)), CEIL(RAND() * 100));
  20.             SET i = i + 1;
  21.         END WHILE;
  22.         COMMIT;
  23.     END$$
  24. DELIMITER ;
  25.  
  26. CALL InsertRand(11111, 12, 65);
  27.  
  28.  
  29. EXPLAIN SELECT * FROM users WHERE age BETWEEN 18 AND 75 ORDER BY num DESC
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top