You are here: The prefered way to update a database, (MySQL) « All PHP « IT news, forums, messages
The prefered way to update a database, (MySQL)

Posted by Simon on 06/09/05 19:11

Hi,

We have a small utility that uses a database.
We are happy with the structure of the database but we cannot predict any
updates.

What we are particularly concerned about are updates vs. new installs.

We have an install that does something like...

.....
CREATE DATABASE "my_db" DEFAULT CHARACTER SET latin1 COLLATE
latin1_swedish_ci;
USE my_db;

CREATE TABLE IF NOT EXISTS "my_table" (
"id" int(11) NOT NULL default '0'
)
....


if we create a new field we would update our install script

....
CREATE TABLE IF NOT EXISTS "my_table" (
"id" int(11) NOT NULL default '0',
"anotherid" int(11) NOT NULL default '0'
)
....

But what about users that already have the table? how can I check if the
field needs to be added?

ALTER TABLE "my_table" ADD "anotherid" INT( 11 ) NOT NULL default '0'

Ideally the script would be self sufficient so we don't have versions to
compare. I would check if the field exists, and if it doesn't alter the
table.

Many thanks in advance.

Simon

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация