Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

What is similar in mssql to $dbh->listfields($tbl) in mysql

by PugSA (Beadle)
on Oct 24, 2006 at 11:26 UTC ( #580239=perlquestion: print w/replies, xml ) Need Help??

PugSA has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

I was recently told to move my MySql db's to MSSQL

I know very little of MSSQL and hope you can help me

1. I use a Mysql module and it has a 'listfields' function to return the column names, do you know of anything similar in MSSQL

Thank you

  • Comment on What is similar in mssql to $dbh->listfields($tbl) in mysql

Replies are listed 'Best First'.
Re: What is similar in mssql to $dbh->listfields($tbl) in mysql
by Tux (Canon) on Oct 24, 2006 at 11:37 UTC
    my $sth = $dbh->prepare ("select * from $tbl where 0 = 1");
    my @names = @{$sth->{NAME_lc}};
    Should work on all databases.
    Other info available in {NAME}, {NAME_uc}, {TYPE}, {PRECISION}, {SCALE}, and {NULLABLE}

    Enjoy, Have FUN! H.Merijn
      Thank You
Re: What is similar in mssql to $dbh->listfields($tbl) in mysql
by gellyfish (Monsignor) on Oct 24, 2006 at 11:53 UTC

    You can use the following query to get the columns in a table from MS SQL Server:

    select from syscolumns join sysobjects on = where = ?
    (you supply the table name as the argument to execute to provide the data for the placeholder.

    Alternatively you can use the INFORMATION_SCHEMA view which basically does the same thing:

    select COLUMN_NAME from information_schema.columns where table_name = ?


Re: What is similar in mssql to $dbh->listfields($tbl) in mysql
by reneeb (Chaplain) on Oct 24, 2006 at 12:49 UTC
    You can also work with the column_info method of DBI.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://580239]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2022-05-24 14:59 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (84 votes). Check out past polls.