how to copy a database

From: Allan Juul (lambretta_at_inet.uni2.dk)
Date: 10/23/03


Date: Thu, 23 Oct 2003 20:41:57 +0200
To: dbi-users@perl.org

hi

IN A NUTSHELL:

   how to copy a database (by scripting)

i want to copy a database from a development environment exactly (or
perhaps as specified in a configuration files) as it is to a production
environment. i wish to do this by running a single perl script.

1)
In SQL Server it's possible in the Enterprise Manager GUI to script all
tables, which will generate one long sql statement that can be executed
and then used to create a fresh new database with all the right
dependencies and keys and no content - after that one can import
content from the source tables.
That's fine one or two times but rather tedious and error-prone in the
long run.
So my question is:

   is it possible to achieve the same kind of script possibly via the
$dbh->tables(), $dbh->table_info() methods ?

[i rewrote the table info example from the DBI Book sources but i would
really like to get my hands on a more robust and elaborate example for
SQL server if anyone has one]

2)
assuming i then have a fresh new database and now want to import the
content, i have found a scripting solution by "backsticking" using the
BCP util - this is almost perfect apart from the fact that it won't
work in transaction mode with AutoCommit off [this again isn't a
problem on a completely new database but maybe i want to use the
procedure on an existing database and only update some of its tables]
So the questions is:

   how do you import/export data from the source tables entirely using
perl ?

3) lastly, how do people deploy stuff to other environments? Surely i'm
not the first one facing this task ;)

many thanks in advance
./allan



Relevant Pages

  • Re: Cannot Open SQL Server Table in Access.ADP File.
    ... Other possiblities would be that you didn't refresh the database window ... I have an SQL Server 2005 database which functions properly with my ... the Generate Script Wizard to recreate the SQL Server Database. ... Then, If I attempt to open another table, it opens. ...
    (microsoft.public.access.adp.sqlserver)
  • Re: SQL Security
    ... except I'm having problems making it work in a script. ... ;Set properties of DB objects and open connection to database ... > from Books Online (within the SQL Server program group): ... > communicate with SQL Server. ...
    (microsoft.public.sqlserver.server)
  • Re: Connecting to SQL Server Express 2005
    ... Microsoft KB (which was referenced in the very useful DataBase Journal ... generated script against my test database. ... The SQL server produced the following list of errors: ... Line 2: Incorrect syntax near 'GO'. ...
    (microsoft.public.sqlserver.connect)
  • RE: Project Server 2003
    ... when I got to the run script step, I ran the script from the copied database ... I was also wondering about the create database ... For example, type Project Server, and then click OK. ... In the left pane of SQL Server Management Studio, expand Databases, ...
    (microsoft.public.windows.server.sbs)
  • Re: Database Access
    ... Do you create the group in SQL Server on the NT Domain? ... >> from a client script to ... > the database server would not be possible from client machines. ... You will want the sqloledb connection string. ...
    (microsoft.public.scripting.jscript)