Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. delimiter //
  2. create procedure setBooks()
  3. begin
  4. set @i = 1;
  5. loop1: loop
  6. set @authorId = (
  7. select id from authors order by rand() limit 1
  8. );
  9. set @themeId = (
  10. select id from themes order by rand() limit 1
  11. );
  12. insert into books (
  13. name, pages, price, publishDate, authorId, themeId
  14. ) values (
  15. concat('book', @i), floor(rand() * 500) + 20,
  16. rand() * 500000 / 100 + 100,
  17. current_timestamp(), @authorId, @themeId
  18. );
  19. set @i = @i + 1;
  20. if @i > 500 then leave loop1; end if;
  21. end loop loop1;
  22. end//
  23. delimiter ;
  24.  
  25. call setBooks();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement