SQL Server 2005: When copy table structure to other database "CONSTRAINT" keywords lost
Posted
by StreamT
on Stack Overflow
See other posts from Stack Overflow
or by StreamT
Published on 2010-04-27T20:12:57Z
Indexed on
2010/04/27
20:33 UTC
Read the original article
Hit count: 284
Snippet of original table:
CREATE TABLE [dbo].[Batch](
[CustomerDepositMade] [money] NOT NULL
CONSTRAINT [DF_Batch_CustomerDepositMade] DEFAULT (0)
Snippet of copied table:
CREATE TABLE [dbo].[Batch](
[CustomerDepositMade] [money] NOT NULL,
Code for copy database:
Server server = new Server(SourceSQLServer);
Database database = server.Databases[SourceDatabase];
Transfer transfer = new Transfer(database);
transfer.CopyAllObjects = true;
transfer.CopySchema = true;
transfer.CopyData = false;
transfer.DropDestinationObjectsFirst = true;
transfer.DestinationServer = DestinationSQLServer;
transfer.CreateTargetDatabase = true;
Database ddatabase = new Database(server, DestinationDatabase);
ddatabase.Create();
transfer.DestinationDatabase = DestinationDatabase;
transfer.Options.IncludeIfNotExists = true;
transfer.TransferData();
© Stack Overflow or respective owner