Getting the schema for a DB table

Simon Wistow simon at thegestalt.org
Sun May 25 17:46:45 BST 2014


[ Continuing the series of "Simon doesn't really do Perl (or 
programming) that much anymore and therefore asks dumb questions" ]

I'm looking for something that can be pointed at a DB table and can give 
the schema for the table back - preferably in the form of an SQL CREATE 
TABLE statement but I can live without[*].

DBIx::DBSchema seems to be just the ticket 

  my $schema = DBIx::DBSchema->new_native($dbh);
  my $sql    = $schema->table($table)->sql_create_table($dbh);

Except I've been running into a bunch of bugs. 

Any other solutions? 

Alternatively - what I'm really trying to do is get a unique finger 
print for the schema of a database. My current plan is hashing the 
CREATE TABLE statement but other methods would be gratefully received.

Simon

[*] Of course in MySQL I can do SHOW CREATE TABLE ... but that's not 
portable.


More information about the london.pm mailing list