List:General Discussion« Previous MessageNext Message »
From:David T-G Date:December 28 2002 1:15am
Subject:style question: "drop database" in an install script
View as plain text  
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi, all --

I'm working up the schema for my application and, as you can imagine,
starting over and reloading numerous times :-)  In fact, I intend for the
script to be an install script, run on a new installation of the software
to set things up.

The script starts out

  drop database if exist dbname ;
  create database dbname ; use dbname ;
  create table tablename
  (
    ...
  ) ;
  ...

to set things up and then continues

  insert into tablename (field,field,field)
    ( data , data , data ) ,
    ...
    ( data , data , data ) ;
  ...

to set up the predefined things (credit card types and so on).

To reload the database and try something new, all I have to do is

  mysql -udroot -p < script.sql

and what was there goes away and is rebuilt fresh.  That's mighty
convenient as I'm building up a table's design and trying it out.

Soooooo...  When you experienced folks write software that's meant to be
installed from a script or such, do you lead off with a 'drop database'
command, or is that just too dangerous to put in a script and you make
your users clean up any old installation by hand?  This will have to be
run by a root user, so we can figure that this user might have read the
docs and know that he's going to start [over] from scratch, but then,
again, users are users :-)

Meanwhile, is there if/then/else functionailty in SQL so that I can say

  if exist dbname exit "some error" ;
  create database dbname ;
  ...

and not try to create and populate a database on top of an existing one?
Or is there perhaps a "RENAME DATABASE" command (I saw RENAME TABLE) so
that I could rename the old one to get it out of the way but not toss it?


TIA & HAND

mysql query,
:-D
- -- 
David T-G                      * There is too much animal courage in 
(play) davidtg@stripped * society and not sufficient moral courage.
(work) davidtgwork@stripped  -- Mary Baker Eddy, "Science and Health"
http://www.justpickone.org/davidtg/    Shpx gur Pbzzhavpngvbaf Qrprapl Npg!

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (FreeBSD)

iD8DBQE+DPsqGb7uCXufRwARAsp8AKC7BuVdyO7Dl5fkbvEM51o+i/BAEgCeI5iI
dI7HQb5oywLHuZIjLxXYZwY=
=QTHL
-----END PGP SIGNATURE-----
Thread
style question: "drop database" in an install scriptDavid T-G28 Dec
  • ORDER dilemmaPag28 Dec
    • RE: ORDER dilemmaJohn Coder28 Dec
      • Re: ORDER dilemmaDan Nelson28 Dec
  • Re: style question: "drop database" in an install scriptiConnect \(Berlin\) Stefan Hinz28 Dec
  • RE: style question: "drop database" in an install scriptArthur Fuller30 Dec
    • Re: style question: "drop database" in an install scriptDavid T-G30 Dec
Re: style question: "drop database" in an install scriptDavid T-G28 Dec