#TEST용 데이터 생성
DELIMITER $$
DROP PROCEDURE IF EXISTS `random_insert_in_table`$$
CREATE PROCEDURE `random_insert_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(
'INSERT INTO ', mTableName, '\n',
'(', '\n',
GROUP_CONCAT(
CONCAT('\t', '`', COLUMN_NAME, '`') SEPARATOR ',\n'
), '\n',
')', '\n',
'VALUES', '\n',
'(', '\n',
GROUP_CONCAT(
CASE DATA_TYPE
WHEN 'varchar' THEN CONCAT('''',RIGHT(UUID(), 8),SUBSTRING(DATE_FORMAT(NOW(3), '%d-%b-%y %H:%m:%s.%f'),21,4),'''')
WHEN 'timestamp' THEN CONCAT('''',NOW(),'''')
WHEN 'datetime' THEN CONCAT('''',NOW(),'''')
WHEN 'float' THEN CAST(RIGHT(RAND(),5) AS DOUBLE)
WHEN 'longtext' THEN NULL#CONCAT('''',LEFT(UUID(), 8),'''')
WHEN 'tinyint' THEN RIGHT(RAND(),1)
WHEN 'smallint' THEN RIGHT(RAND(),3)
WHEN 'int' THEN SUBSTRING(DATE_FORMAT(NOW(3), '%d-%b-%y %H:%m:%s.%f'),20,3)
WHEN 'double' THEN SUBSTRING(DATE_FORMAT(NOW(3), '%d-%b-%y %H:%m:%s.%f'),18,5)
END
), '\n',
')', '\n'
)
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'test'
AND TABLE_NAME = mTableName
AND COLUMN_NAME NOT IN ('send_yn', 'send_date', 'missed_yn', 'faultDesc')
);
EXECUTE IMMEDIATE @Query;
END LOOP;
CLOSE cur;
END$$
DELIMITER ;
CALL random_insert_in_table();
'DB > MariaDB' 카테고리의 다른 글
MariaDB 데이터 파일 저장 경로 변경 (0) | 2022.04.01 |
---|---|
MariaDB 모든 테이블 데이터 삭제 (0) | 2022.03.24 |
MariaDB cs파일 코드 생성 (0) | 2022.03.24 |