Generate tables data in a .sql using SMO
hello,
i'am working on project , need generate tables data in separate files in form of inserts can executes files in other dbs have same shemas.
also, want edit insert queries can have :
insert table_name ('val1','val2','val3')
instead of :
insert table_name ('column 1','column 2','column 3') values ('val1','val2','val3')
all using smo.
thank :).
you'd better off using 3rd party product red gate sql data compare. can come close using smo, there isn't option script data , remove column list. here's a powershell script script create tables plus data:
add-type -assemblyname "microsoft.sqlserver.connectioninfo, version=10.0.0.0, culture=neutral, publickeytoken=89845dcd8080cc91" add-type -assemblyname "microsoft.sqlserver.smo, version=10.0.0.0, culture=neutral, publickeytoken=89845dcd8080cc91" add-type -assemblyname "microsoft.sqlserver.smoextended, version=10.0.0.0, culture=neutral, publickeytoken=89845dcd8080cc91" $sourcesrv = "$env:computername\sql1" $sourcedb = "northwind" $server = new-object ("microsoft.sqlserver.management.smo.server") $sourcesrv $db = $server.databases[$sourcedb] $transfer = new-object ("microsoft.sqlserver.management.smo.transfer") $db $transfer.options.withdependencies = $false $transfer.copyallobjects = $false $transfer.copyalltables = $true $transfer.options.scriptdata = $true $transfer.enumscripttransfer()
SQL Server > SQL Server SMO/DMO
Comments
Post a Comment