Sunday, 8 August 2010

mysql stored procedure example

This is an example script of mysqls stored procedure.
This will insert a large number of records into a table. I prepared this for checking the performance of db.


delimiter //
CREATE PROCEDURE load_part_tab()
begin
declare v int default 0;
declare latv,longv float;

while v < 8000000
do

set latv = FLOOR(7 + (RAND() * 5)) + rand();
set longv = FLOOR(7 + (RAND() * 5)) + rand();

INSERT INTO `sams`.`latlong` (
`id` ,
`lat` ,
`lng` ,
`place_name`
)
VALUES (
'', latv, longv, concat(latv,longv));

set v = v + 1;
end while;
end
//
delimiter ;

No comments:

Post a Comment

Please share your thought about this