Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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 pondering the Monastery: (4)
As of 2022-06-25 22:18 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (83 votes). Check out past polls.