how to I get the the column name with table names. thanks

Something like this might help:

#!/usr/bin/perl use strict; use warnings; use Win32::ODBC; my $db = new Win32::ODBC("DSN") or die Win32::ODBC::Error(); my @table_list = $db->TableList(); my %tables; for my $table ( @table_list ) { if ( $db->Sql("Select * from $table") ) { print "Error: " . $db->Error() . "\n"; $db->close(); exit; } else { @{$tables{$table}} = $db->FieldNames(); } } $db->Close(); foreach my $table ( keys %tables ) { print "TABLE $table CONTAINS:\n"; foreach my $column ( @{$tables{$table}} ) { print "\t$column\n"; } }
You've mentioned you already know how to get the length. Another method you might want to look at is DBD::ODBC using DBI which might make some things easier (I prefer it to Win32::ODBC) anyhow here is some code using DBI to get the information you ask:
#!/usr/bin/perl use strict; use warnings; use DBI; my $dbh = DBI->connect("dbi:ODBC:table","name","password") or die $DBI::errstr; my $sth_t = $dbh->table_info(); my @tables; while (my $table = ($sth_t->fetchrow())[2] ) { #Comment out next line if MSys* tables wanted #which might just be an Access thing anyhow next if $table =~ /^MSys/; push @tables,$table; } printf "%20s %20s %20s\n", 'TABLE','COLUMN NAME', 'COLUMN SIZE'; foreach my $table ( @tables ) { my $sth_c = $dbh->column_info( undef, undef, $table, undef ); while ( my ($table_name,$column_name, $column_size ) = ($sth_c->fetchrow())[2,3,6] ) { printf "%20s %20s %20s\n", $table_name, $column_name, $column_size; } } $dbh->disconnect();

-enlil


In reply to Re: Table name and COLUMN Names by Enlil
in thread Table name and COLUMN Names by developer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.