mySQL: size of the database

SELECT table_schema "Database",
 sum( data_length + index_length ) / 1024 / 1024 "Size (MB)",
 sum( data_free )/ 1024 / 1024 "Free (MB)"
FROM information_schema.TABLES
GROUP BY table_schema ;

This will work in mySQL 5.0.2 and newer. Use SHOW TABLE STATUS command for [...]

MS SQL & Sybase: recreate master database

Sybase:
before 12.5: buildmaster (bldmatr for NT)

buildmaster -d master_device -s size_in_2k_pages

12.5 and later: dataserver with some options (sqlsvr for NT)

dataserver -d master_device -b size -forcebuild -z page_size -Z size_of_master_db

MS SQL:

before MS 2005:
rebuildm utility (GUI)

MS SQL 2005:

Start server in single-user mode (sqlserver.exe -m)
setup.exe /qn INSTANCENAME=instance_name REINSTALL=SQL_Engine REBUILDDATABASE=1 SAPWD=new_SA_Password
Restart server in [...]

Process all databases in Sybase

#!/usr/bin/ksh
echo "Started…"

print -u2 -n "Enter password:"
stty -echo
read PASS
stty echo
print

rm -f databases.lst
isql -U sa -S $DSQUERY -w 999<<EOF | awk ‘/DBLABEL/ { print $2 }’ > databases.lst
$PASS
select ‘DBLABEL’ "XXX", name from master..sysdatabases
go
exit
EOF

for DB in $(cat databases.lst) ; do

print -u2 "Processing $DB …"
isql -U sa -S $DSQUERY -w 999 -D $DB <<EOF
$PASS

– some commands here
go

exit
EOF
done

print [...]