Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Automatically altering tables from different schema's

by VSarkiss (Monsignor)
on Jan 08, 2004 at 17:50 UTC ( [id://319878]=note: print w/replies, xml ) Need Help??


in reply to Automatically altering tables from different schema's

I can't give you any pointers to specific code, but I want to point out that the problem is more subtle than you may think. For example, take your second foo table. Is it different from this:

create table foo ( status tinyint, id int primary key, name varchar(255) )
As a human, you can see that the difference is mainly in column order, but also the id and status columns are not qualified as "unsigned". The question is, do these differences matter to you?

If you're a programmer and you have well-written SQL, then column order in a table does not matter. On the other hand, if you're a DBA, and you're managing a million-row table with varchar(4000) columns, then column order does matter.

It turns out that identifying the differences and overcoming them is mostly the same problem. Even if you can't make the change with an ALTER statement, you could always create a new table and load it from the old one, then rename the results. But the crux of the problem remains: what do you consider a significant difference? Once you've figured that out, the right tool to use will be easier to select.

HTH

Replies are listed 'Best First'.
Re: Re: Automatically altering tables from different schema's
by mpeppler (Vicar) on Jan 08, 2004 at 18:14 UTC
    I want to point out that the problem is more subtle than you may think
    Indeed. The difference between two versions of a table can be missing columns, which is fairly easy to manage, or more subtle things like NULL/NOT NULL, primary key, constraints, and a host of other things.

    Consider Sybase's CREATE TABLE syntax:

      I was going to go for MySQL and SQLite, because those are the itches that I need to scratch. Other will have to add their favourite database drivers themselves ;-)

      Liz

Re: Re: Automatically altering tables from different schema's
by liz (Monsignor) on Jan 08, 2004 at 18:21 UTC
    ...the difference is mainly in column order...

    I was thinking of not considering these significant. Well, not in the initial version (I was thinking hashes rather than diffs ;-).

    ...but also the id and status columns are not qualified as "unsigned"...

    I would consider those significant. Database engines might just change a flag in the format instead of updating each field: that's their business.

    ...you could always create a new table and load it from the old one, then rename the results...

    That would be the database independent fallback. But since renaming a table is not standard SQL (is it, it would involve:

    1. creating a temporary table
    2. dumping the table data in there
    3. drop the original table
    4. create with new schema
    5. copy the data back over
    6. drop the temporary table

    Liz

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://319878]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-25 09:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found