Yesterday while I was writing script for SQL SERVER – 2005 – Find Unused Indexes of Current Database . I realized that I needed SELECT statement where I get the name of the current Database. It was very simple script.
SELECT DB_NAME() AS DataBaseName
It will give you the name the database you are running using while running the query.
Reference : Pinal Dave (http://blog.SQLAuthority.com)