Retrieving connection database name that I am currently running a statement on.

  • How do I find out what database I am connected to?

    Example:

    USE DB1

    SET DB_Name = (?)

    PRINT 'You are currently using ' + DB_Name

    Results is:

    You are currently using DB1

  • You are very close.

    [font="System"]declare @current_db sysname;

    set @current_db = db_name();

    select 'The current DB is ' + @current_db;[/font]

    Thanks,

    Eric

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply