correlation https://teguhth.blogspot.com/2026/04/sync-manual-table-add-column-alter_10.html
1. CREATE TABLE (yang belum ada di aisyah)
DELIMITER $$
CREATE PROCEDURE sp_compare_table(
IN p_source_db VARCHAR(100),
IN p_target_db VARCHAR(100)
)
BEGIN
SET SESSION group_concat_max_len = 1000000;
SET @sql = CONCAT(
'SELECT
CONCAT(
''CREATE TABLE ', p_target_db, '.'' , t.table_name, '' ( \n'',
GROUP_CONCAT(
CONCAT(
'' '', c.column_name, '' '',
c.column_type,
IF(c.is_nullable = ''YES'', '' NULL'', '' NOT NULL'')
)
ORDER BY c.ordinal_position
SEPARATOR '',\n''
),
''\n);''
) AS create_table_script
FROM information_schema.tables t
JOIN information_schema.columns c
ON t.table_schema = c.table_schema
AND t.table_name = c.table_name
WHERE t.table_schema = ''', p_source_db, '''
AND t.table_name NOT IN (
SELECT table_name
FROM information_schema.tables
WHERE table_schema = ''', p_target_db, '''
)
GROUP BY t.table_name'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END$$
DELIMITER ;
1. CREATE TABLE (yang belum ada di aisyah)
DELIMITER $$
CREATE PROCEDURE sp_compare_table(
IN p_source_db VARCHAR(100),
IN p_target_db VARCHAR(100)
)
BEGIN
SET SESSION group_concat_max_len = 1000000;
SET @sql = CONCAT(
'SELECT
CONCAT(
''CREATE TABLE ', p_target_db, '.'' , t.table_name, '' ( \n'',
GROUP_CONCAT(
CONCAT(
'' '', c.column_name, '' '',
c.column_type,
IF(c.is_nullable = ''YES'', '' NULL'', '' NOT NULL'')
)
ORDER BY c.ordinal_position
SEPARATOR '',\n''
),
''\n);''
) AS create_table_script
FROM information_schema.tables t
JOIN information_schema.columns c
ON t.table_schema = c.table_schema
AND t.table_name = c.table_name
WHERE t.table_schema = ''', p_source_db, '''
AND t.table_name NOT IN (
SELECT table_name
FROM information_schema.tables
WHERE table_schema = ''', p_target_db, '''
)
GROUP BY t.table_name'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END$$
DELIMITER ;

















