The database() function returns the default database, so: mysql> use scratch; Database changed mysql> select database(); +------------+ | database() | +------------+ | scratch | +------------+
mysql> use mysql; Database changed mysql> select database(); +------------+ | database() | +------------+ | mysql | +------------+ However, if the database function is invoked from within a stored procedure, it only returns the name of the database in which it exists: use scratch; delimiter $$ create procedure thisdb() begin select database(); end$$ delimiter ; use scratch; call scratch.thisdb(); scratch use mysql; call scratch.thisdb(); scratch use customer; call scratch.thisdb(); scratch This is documented behavior. Is there anyway for a stored procedure to determine what the deafault schema of the user invoking it is? We are trying to track down cross-schema invocations of sp's and this is the last piece I have to figure out. Thanks, Jim -- Jim Lyons Web developer / Database administrator http://www.weblyons.com