|
|
sybperl-l Archive
Up Prev Next
From: mpeppler at itf dot ch (Michael Peppler)
Subject: Running 'update statistics'
Date: Feb 1 1996 8:46AM
The little script below is quite usefull if you want too make sure that
your index distribution pages are correct (so that the optimizer will
do it's job as well as possible). What I do is I run 'update
statistics' on all the tables owned by 'dbo' in a database.
Michael
#!/usr/local/bin/perl
use Sybase::DBlib;
require 'sybutil.pl';
require 'getopts.pl';
&Getopts('d:');
select(STDOUT); $| = 1; # Make sure output is un-buffered.
die "Please specify a database with -d 'dbname'...\n" if !defined($opt_d);
$dbh = new Sybase::DBlib 'sa', $password;
$dbh->dbuse($opt_d);
@tables = $dbh->sql("select o.name, u.name, o.id
from sysobjects o, sysusers u
where o.type = 'U' and u.uid = o.uid
and u.name = 'dbo'
order by o.name\n");
foreach (@tables)
{
print "update statistics $$_[0]\n";
$dbh->sql("update statistics $$_[0]\n") ||
die "Update statistics failed for $$_[0]\n";
}
|