List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:October 14 2003 6:19pm
Subject:Re: Auto generate MySQL schema based on a text file?
View as plain text  
At 19:05 +0100 10/14/03, Andrew Braithwaite wrote:
>Hi,
>
>Does anyone know of a perl module or other code that can look at a text file
>(CSV, tab-delim etc..) of data and determine a MySQL table definition from
>it?
>
>The data may or may not have a set of column headers as the first line.

You can use the guess_table.pl utility that's part of the software
distribution that accompanies MySQL Cookbook.  The distribution is
available at:

http://www.kitebird.com/mysql-cookbook/

Follow the Downloads link, grab the recipes distribution, unpack it,
and look in the transfer directory.

It requires tab-delimited data. For other formats, you may be able
to use the cvt_file.pl util that's in the same directory to convert
them to tab-delimited.

% guess_table.pl --help
Usage: guess_table.pl [options] [data_file]

Options:
--help
     Print this message
--labels, -l
     Interpret first input line as row of table column labels
     (default = c1, c2, ...)
--lower, --upper
     Force column labels to be in lowercase or uppercase
--quote-names
    Quote table and column names with `` characters (in case they are
    reserved words)
--report , -r
     Report mode; print findings rather than generating a CREATE
     TABLE statement
--table=tbl_name, -ttbl_name
     Specify table name (default = t)



>
>I would appreciate it greatly if anyone could give me any pointers to
>existing stuff as I have to implement this function (and I don't
>particularly like spending my time painfully churning out regexps if it's
>not absolutely necessary!! :)
>
>Cheers,
>
>Andrew
>
>SQL, Query


-- 
Paul DuBois, Senior Technical Writer
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

Are you MySQL certified?  http://www.mysql.com/certification/

Thread
Auto generate MySQL schema based on a text file?Andrew Braithwaite14 Oct
  • Re: Auto generate MySQL schema based on a text file?Paul DuBois14 Oct
RE: Auto generate MySQL schema based on a text file?Andrew Braithwaite14 Oct
  • RE: Auto generate MySQL schema based on a text file?Paul DuBois14 Oct