my $sth1 = $dbh->prepare("SELECT * FROM $table"); $sth1->execute() or die $DBI::errstr; my $col_names = $sth1->{NAME}; foreach my $column ( @{$col_names}) { my $sth = $dbh->column_info(undef, undef, $table, $column); foreach my $col_info ($sth->fetchrow_hashref) { print " $col_info->{'ORDINAL_POSITION'} $col_info->{'COLUMN_NAME'} \n"; } } #### 1 id 1 name 1 start