Re: Script to Compare Database Structures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 31, 2009 at 05:38:44PM -0400, Matt Neimeyer wrote:

> I know I CAN hack something together but I hate to reinvent the wheel.
> 
> I want to be able to compare the structure of two different clients
> databases that might be on different servers that are firewalled away
> from each other. Given the two structures it will list all the SQL
> commands needed to make the database structure the same.
> 
> In a perfect world on one side you would pull up a PHP page that does
> a "generate structure" which would create a downloadable file which
> you could then upload to the other system which would then give a
> listing of the SQL commands needed to make the local structure match
> the uploaded structure.
> 
> Thanks in advance...

I don't know what flavor of SQL you're using, but for SQL-compliant
databases, there is an "information_schema" table (I believe that's the
correct name) which contains most or all of the data you need. Query
that table into an array for each server, and compare the arrays.

Here's a query I've used:

SELECT table_name, column_name, data_type, column_default, is_nullable,
character_maximum_length, numeric_precision, numeric_scale FROM
information_schema.columns WHERE table_name = 'tablename' ORDER BY
ordinal_position

This will not tell you the relations between tables, nor which columns
are primary keys, etc. There may be another way to get this out of
information_schema.

Paul

--
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux