in reply to if table exists (DBI)
Although this thread is 11 years old, since this is a basic question, then for the benefit of PerlMonks users, here is the "right and efficient" answer (in my opinion):
for MS SQL Server:
(Assume the table name you are testing for existence is in variable $table_name):
my $query = "IF EXISTS(SELECT * FROM sys.tables WHERE type = 'U' AND +name = '$table_name') SELECT 1 ELSE SELECT 0"; my $sth = $dbh->prepare( $query ); $sth->execute; my $result = $sth->fetchrow_array;
$result should be 1 if $table_name exists in the database, and vice versa.
Helen
In Section
Seekers of Perl Wisdom