IF EXISTS(SELECT name FROM sys.databases WHERE name=N'Test') BEGIN USE Test EXEC sp_updatestats END GO