Witam posiadam tabele agenci gdzie znajdują się takie kolumny jak licencjat: varchar(30), nazwa: varchar(30), wiek: int, oraz typ("osoba indywidualna", "agencja", "inny"). Chciałbym stworzyć 1000 agentów a później dodać te dane do tabeli. Czy jest jakiś sprawny sposób aby to zrobić czy muszę wymyślać rzeczy tego typu:
CREATE TRIGGER unique_codes_before_update
BEFORE UPDATE ON unique_codes FOR EACH ROW
BEGIN
declare ready int default 0;
declare rnd_str text;
if new.nazwa is null then
while not ready
set rnd_str := lpad(conv(floor(rand()*pow(36,6)), 10, 36), 6, 0);
if not exists (select * from unique_codes where nazwa = rnd_str) then
set new.nazwa = rnd_str;
set ready := 1;
end if;
end while;
end if;
END//
DELIMITER ;