Montag, 1. September 2008

Alle Daten aus Quell in Zieldatenbank kopieren

Funktioniert leider noch nicht bei Tabellen die Identity haben, weil dann eine Spaltenliste übergeben werden muss.

use target db

-- disable referential integrity
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
GO

EXEC sp_MSForEachTable '
if OBJECTPROPERTY(object_id(''?''), ''TableHasIdentity'') = 1
set identity_insert on

Insert into ? SELECT * sourcedb.?

if OBJECTPROPERTY(object_id(''?''), ''TableHasIdentity'') = 1
set identity_insert ? off

'
GO

-- enable referential integrity again
EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
GO