DELIMITER $$
DROP PROCEDURE IF EXISTS `random_delete_in_table`$$
CREATE PROCEDURE `random_delete_in_table`()
BEGIN
DECLARE mTableName VARCHAR(50) DEFAULT '';
DECLARE mEndOfRow INT DEFAULT 0;
DECLARE cur CURSOR FOR
SELECT
TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'test'
AND TABLE_NAME NOT LIKE '%batch%';
DECLARE CONTINUE HANDLER FOR NOT FOUND SET mEndOfRow = 1;
OPEN cur;
read_loop : LOOP
FETCH cur INTO mTableName;
IF mEndOfRow = 1 THEN
LEAVE read_loop;
END IF;
SET @Query = (
SELECT CONCAT(
'DELETE FROM ', mTableName
)
);
EXECUTE IMMEDIATE @Query;
END LOOP;
CLOSE cur;
END$$
DELIMITER ;
CALL random_delete_in_table();
'DB > MariaDB' 카테고리의 다른 글
MariaDB 데이터 파일 저장 경로 변경 (0) | 2022.04.01 |
---|---|
MariaDB 모든 테이블 랜덤 값 insert (0) | 2022.03.24 |
MariaDB cs파일 코드 생성 (0) | 2022.03.24 |