×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: SQL
Posted by: Kirill Lobastov
Added: Jun 22, 2015 4:28 AM
Views: 12
Tags: mysql
  1. DROP PROCEDURE update_id_in_files;
  2. DELIMITER //
  3. CREATE PROCEDURE  update_id_in_files()
  4.         BEGIN
  5.                 DECLARE count_video INT;
  6.                 SELECT COUNT(*) INTO count_video FROM videos;
  7.  
  8.                 WHILE count_video > 0 DO
  9.  
  10.                         UPDATE video_files SET video_id = (
  11.                                 SELECT id FROM videos WHERE dir = (
  12.                                         SELECT dir FROM videos WHERE id = count_video
  13.                                 )
  14.                         ) WHERE video_id = (SELECT dir FROM videos WHERE videos.id = count_video );
  15.  
  16.                         SET count_video = count_video-1;
  17.                 END WHILE;
  18.         END;
  19. //