HOWTO create a copy of one database

  • Thread starter Thread starter Lars Grøtteland
  • Start date Start date
L

Lars Grøtteland

Hello!

Was wondering how I can create a copy of one database? FYI I'm not
interrested in the data, just the fields and triggers, and so on.

Which way is the easiest? Do I create a script and run it from there? Is it
smart to have it inside a SP?

Any idea would be greatly appreciated.

I'm programming SQL 2k and VC7.0
 
Lars
Right click on the database then All tasks then Generate SQL Script.
Save it as .sql (or whatever) file and you can run it from QA or later if
you need from the file.
 
Yes I know I can do this in QA, but how to do it in my application?

Was thinking of making a SP, inside the model database. I think I've read of
this database once - that if I create one SP inside this, this should be
copied to the new database that's been created. Is this a solution?
 
Yes, stuff from model are copied to a new database. But this seems to be a
real awkward way of doing it. Just generate the scrip and have your
application loop the script file and for each "GO" it encounters in the file
is executes what you have built in the buffer so far.
 
If you want to do it from inside you application, use SQL-DMO. You can copy
the complete database without using a script with the Database.Transfer
method, or you can generate a script with the Database.Script method. Both
method have a rather long list of parameters, which is a bit too much to
mention here, but whihc you can find in Books Online. The parameters
basically allow you all the options you have when copying a database or
generating a script from Enterprise Manager.
 
Then I have another trick for you!

I have "GOTO" inside the script. What should I do then?
 
Back
Top