Better version here https://gist.github.com/tcartwright/615053acde5ea64d1664ef6f9faa6524
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@rem bat file to ease use of the script | |
@%~d0 | |
@cd "%~dp0" | |
powershell.exe -ExecutionPolicy Bypass -NoLogo -NoProfile -file "%~dpn0.ps1" | |
@echo Done. | |
@pause |
Moved this script to a fork of Barbaras: https://gist.github.com/tcartwright/615053acde5ea64d1664ef6f9faa6524
Converted into a module: https://github.com/tcartwright/tcdbtools
PS Gallery link: https://www.powershellgallery.com/packages/tcdbtools/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
USE master | |
IF OBJECT_ID (N'dbo.sp_generate_merge_crud') IS NULL BEGIN | |
EXEC('CREATE PROCEDURE dbo.sp_generate_merge_crud AS SELECT ''PROCEDURE STUB, TO BE REPLACED'';'); | |
END | |
GO | |
/* | |
TIM C: Because of issues with the MERGE statement (https://www.mssqltips.com/sqlservertip/3074/use-caution-with-sql-servers-merge-statement/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Original script from here: https://karaszi.com/restore-all-databases-from-a-number-of-backup-files | |
Tim C: made a modification so the script adjusts the columns per the SQL Server version | |
*/ | |
IF OBJECT_ID (N'dbo.GetBackupRestoreHeaders') IS NULL BEGIN | |
EXEC('CREATE PROCEDURE dbo.GetBackupRestoreHeaders AS SET NOCOUNT ON;'); | |
END | |
GO | |
ALTER PROCEDURE dbo.GetBackupRestoreHeaders ( | |
@backup_file_path VARCHAR(8000), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Original script from here: https://karaszi.com/restore-all-databases-from-a-number-of-backup-files | |
Tim C: made a modification so the script adjusts the columns per the SQL Server version | |
*/ | |
DECLARE @backup_file_path VARCHAR(500) = 'path to backup file.bak' | |
IF OBJECT_ID('tempdb..#restore_headeronly') IS NOT NULL BEGIN | |
DROP TABLE #restore_headeronly | |
END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Original script from here: https://karaszi.com/restore-all-databases-from-a-number-of-backup-files | |
Tim C: made a modification so the script adjusts the columns per the SQL Server version | |
*/ | |
DECLARE @backup_file_path VARCHAR(500) = 'path to backup file.bak' | |
IF OBJECT_ID('tempdb..#restore_filelistonly') IS NOT NULL BEGIN | |
DROP TABLE #restore_filelistonly | |
END |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN -- SETUP FAKE SOURCE AND DESTINATION | |
IF OBJECT_ID('tempdb..#destination') IS NOT NULL BEGIN | |
DROP TABLE #destination | |
END | |
CREATE TABLE #destination ( | |
id INT NOT NULL IDENTITY, | |
name VARCHAR(100), | |
number INT | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- only create the temp table #partitions ONCE. DROP if needed to recreate | |
-- DROP TABLE #partitions | |
IF OBJECT_ID('tempdb..#partitions') IS NULL BEGIN | |
-- table to hold all of the partition information | |
CREATE TABLE #partitions ( | |
database_id int NOT NULL, | |
database_name sysname NOT NULL, | |
partition_id bigint NOT NULL, | |
object_id INT NOT NULL, |