Mysql
 SQL >> Datenbank >  >> RDS >> Mysql

Werte aus einem Bereich automatisch in eine Tabelle einfügen

Eine Stored Procedure kann eine Schleife verwenden:

CREATE PROCEDURE insert_range()
BEGIN
    DECLARE i INT DEFAULT 30;

    WHILE i <= 200 DO
        INSERT INTO my_table (col_with_range) VALUES (i);
        SET i = i + 1;
    END WHILE;
END

Die Prozedur läuft von 30 bis 200 und fügt jeden Wert in col_with_range ein.