Hi,
I just wonder if someone can help me with this:
I need to create a sql script which will run when user installs/upgrades my app.
User may already have the database and tables tructure setup on the server, or may not.
The script needs to conditionally create database, conditionally create tables, and conditionally
add columns to the tables if needed.
I could perform this on MS SQL, as the master database has all info about all other
databases/tables/schemas. BUt in MySQL i don't see such an option.
So, i would need this(for description i use a mix of SQL and pseudo-language):
// -------------- CODE START
IF NOT EXISTS( MyDatabase ) CREATE MyDatabase;
USE MyDatabase;
IF NOT EXISTS( MyTable )
CREATE MyTable (
Field1 INT NOT NULL,
Field2 VARCHAR(20),
Field3 INT
)TYPE='MyISAM'
IF NOT EXISTS (Field3 IN MyTable)
ALTER TABLE MyTable ADD Field3 INT
..... etc...
// -------------- CODE END
So if someone could show me the MySQL way to do that, i would really appreciate that!
Thank you,
Andrey