/*
10.10.2024, TSC
*/
USE master;
DECLARE @dbg BIT = 0;

SELECT 
    @@SERVERNAME AS [db_server]
    ,s.[name] AS [snapshot]
    ,s.[database_id] AS [sn_id]
    ,d.[name] AS [source_database]
    ,d.[database_id] AS [db_id]
    ,s.[create_date] 
    ,REPLACE(REPLACE(REPLACE('EXEC [master].[dbo].[p_DbTool__Recreate_Snapshot] @debugMode = @dbg@, @databaseName = ''@db_name@'', @snapshotName = ''@snapshot_name@'';', '@dbg@', @dbg), '@db_name@', d.[name]), '@snapshot_name@', s.[name]) AS [recreate_script]
    ,REPLACE(REPLACE(REPLACE('EXEC [master].[dbo].[p_DbTool__Drop_Snapshot] @debugMode = @dbg@, @databaseName = ''@db_name@'', @snapshotName = ''@snapshot_name@'';', '@dbg@', @dbg), '@db_name@', d.[name]), '@snapshot_name@', s.[name]) AS [drop_script]
FROM [sys].[databases] s
    JOIN [sys].[databases] d ON d.[database_id] = s.[source_database_id]
ORDER BY REPLACE(REPLACE(d.[name],'__00',''), '__01', ''), s.[name];