Skip to content

Neue Datenbank Konsole Befehle (DBCC) CLONEDATABASE

Sie haben es vielleicht noch nicht gesehen, aber mit den Service Pack 2 von SQL Server 2014 gibt es einen neuen DBCC Befehl: CLONEDATABASE.

„DBCC CLONEDATABASE sollte Kopien eines Schemas und den Statistiken einer Produktionsdatenbank erstellen, um bei Leistungsproblemen Abfragen zu untersuchen.“ MSDN Quelle finden wir hier.

Dieser Befehl kann nur Benutzedatenbanken klonen.

Clonedatabase01

Wie Sie sehen, für die Systemdatenbanken ist es nicht möglich, denn es treten Fehlermeldungen auf:
Msg 12603, Level 16, State 1, Line 5
DBCC CLONEDATABASE does not support cloning system databases.

Mit DBCC CLONEDATABASE wird eine neue Datenbank erstellet. Es ist ein interner Snapshot der die Systemmetadaten, alle Schemas und alle Statistiken für alle Indizes kopiert. Deswegen, ist die Datenbank leer und ist im Read-Only Modus.
Clonedatabase02

Die Schemas sind kopiert… Ok, ich werde jetzt mit SQL Server Data Tools (SSDT) ein «Schemavergleich» durchführen:
Clonedatabase03

Alle Schemas sind in der geklonten Databank. Die Änderungen sind für den Fulltext und die Daten im XML Schema, wie zum Beispiel der MileRangeType mit seiner Bedeutung.
Clonedatabase04

Ich habe mit meinem Freund Michel über diese Funktionalität gesprochen und er hat mir gefragt wie verhaltet es sich mit den Daten?
Mein erster Schritt ist es die Betrachtung der Dateistruktur nach dem Klonen :
Clonedatabase05
Sie können feststellen, dass meine geklonte Datenbank weder die Benutzerdatenbank noch die Modeldatenbank übernommen hat.
Ich richte eine neue Filegroup [FG_Employees] ein, mit ein neue File AdventureWorks2014_Employees.ndf
Ich ändere mein Clustered Indize PK_Employee_BusinessEntityID zu dieser neuen Filegroup:

USE [master]
GO
ALTER DATABASE [AdventureWorks2014] ADD FILEGROUP [FG_Employees]
GO
ALTER DATABASE [AdventureWorks2014]
ADD FILE ( NAME = N'AdventureWorks2014_Employees',
FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL12.TEST\MSSQL\DATA\AdventureWorks2014_Employees.ndf'
, SIZE = 16384KB , FILEGROWTH = 8192KB ) TO FILEGROUP [FG_Employees]
GO
USE [AdventureWorks2014];
GO
CREATE UNIQUE CLUSTERED INDEX PK_Employee_BusinessEntityID
    ON HumanResources.Employee(BusinessEntityID)
WITH (DROP_EXISTING =  ON )
ON [FG_Employees]

Und jetzt, klone ich wieder meine Datenbank:
Clonedatabase06
Die Dateistruktur ist kopiert, cool!
Kann ich die Datenbank auf Read-Only ändern und Datei importieren?

USE [master]
GO
ALTER DATABASE [AdventureWorks2014_clone] SET  READ_WRITE WITH NO_WAIT
GO
INSERT INTO [AdventureWorks2014_clone].[Sales].[Currency]
SELECT *  FROM [AdventureWorks2014].[Sales].[Currency]

Kein Problem, die Daten sind direkt kopiert.
Clonedatabase07

Diese neue Funktionalität ist wirklich einfach zu verwenden.
Ich hoffen dass im nächsten Service Pack von SQL Server 2012 und SQL Server 2016 die CLONEDATABASE Funktion auch integriert wird. Für mehr Information, MSDN link hier

Let’s work together

Ready to operate at
the next level?

Tell us about your challenge. We’ll bring the depth, the expertise, and the Swiss precision.

Stéphane Haby

Stéphane Haby

Stéphane Haby has more than 20 years of experience in Microsoft solutions, specializing in the installation, migration, best practices, and performance analysis of Microsoft SQL Server, as well as Microsoft Business Intelligence solutions (SharePoint, Office) and .NET development for the banking sector. A former Microsoft Most Valuable Professional (MVP) and early adopter of Microsoft Team System in France, he has authored several technical articles. He holds Microsoft Certified Solutions Associate (MCSA) and Expert (MCSE) for SQL Server, MCTS, MCITP for SQL Server 2008, and ITIL V3 Foundation certifications. His industry experience covers chemicals and pharma, banking, and financial services.View Author posts

182 posts since April 2011

Most read in Database

The Database posts our readers open most: the all-time favourites, and what is trending right now.

Leave a Comment

Your email address will not be published. Required fields are marked *