Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by PugSA (Beadle)
on Oct 24, 2006 at 11:26 UTC ( [id://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

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");
    $sth->execute;
    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 reneeb (Chaplain) on Oct 24, 2006 at 12:49 UTC
    You can also work with the column_info method of DBI.
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 syscolumns.name from syscolumns join sysobjects on sysobjects.id = syscolumns.id where sysobjects.name = ?
    (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 = ?

    /J\

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2024-03-28 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found