How to sync schema continuously in two databases in Sql Server (for unit testing) -


we have database against run unit tests components require database (for several reasons not mocking dal everywhere).

we using sql server 2008 r2 , in development db server have our development database (applicationname_dev) , our testing db (applicationname_ut).

the unit tests create test data need , delete afterwards tables could/should empty when no tests running.

the problem keeping schema of unit test database date.

the best solution me (to limited knowledge) have sql server agent job run once night (or when manually started) drops tables in ut database, generate create script tables, indexes , relationships in dev-database, , run create scripts on ut-database. note don't need insert data.

is there way of programmatically (t-sql, smo etc) generating create scripts tables including indexes , relationships?

in management studio can right click database->tasks->generate scripts...->choose objects->tables , scripts want (except "use [applicationname_dev]" on first line.

please help.

regards, mathias

i'd create ssis package - there's task called "transfer sql server objects task". specify source , destination connections & databases, set dropobjectsfirst true, , copyallobjects (or copyalltables , copyallviews) also, , should set. (and obviously, don't set copydata true).

you need set copyindexes , other such table options, table structures want.

setting job run ssis package quite easy.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -