how to I get the the column name with table names. thanks
Something like this might help:
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 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"; } }
#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |