Up Prev Next
From: "Edward J dot Sabol" <sabol at alderaan dot gsfc dot nasa dot gov>
Subject: Re: listing tables from within DBD::Sybase
Date: Sep 27 2001 8:19PM
Ed Phillips asked:
> I have a question that I did not see addressed in the docs.
> I've got a remote database I'm working with. Is there a
> command callable from DBD::Sybase that will give me a list of
> the tables in my database; does this command also work on
> MSSQL databases?
>> You will probably have to do a select from the
>> sysdatabases table, like so:
>> select name from sysdatabases order by name
>> I don't think DBD-Sybase has a specific command or routine
>> that returns table names.
Of course it does. Please refer to the table_info method of the DBI
documentation ("perldoc DBI").
my $dbh = DBI->connect(...);
my $sth = $dbh->table_info;
my $array_ref = $sth->fetchall_arrayref;
$array_ref will then look like this:
[ [ mydatabase, dbo, sysalternates, SYSTEM TABLE, ],
[ mydatabase, dbo, sysattributes, SYSTEM TABLE, ],
[ mydatabase, dbo, syscolumns, SYSTEM TABLE, ],
[ mydatabase, dbo, syscomments, SYSTEM TABLE, ],
[ mydatabase, dbo, sysconstraints, SYSTEM TABLE, ],
[ mydatabase, dbo, sysdepends, SYSTEM TABLE, ],
The columns returned are labelled as [ table_qualifier, table_owner,
table_name, table_type, remarks ], where table_qualifier in the Sybase realm
means the name of the database that you are connected to in $dbh.