How can I query the name of the current SQL Server database instance?

后端 未结 7 1578
后悔当初
后悔当初 2020-12-06 04:27

It is a bit of a \"chicken or egg\" kind of query, but can someone dreamup a query that can return the name of the current database instance in which the query executes? Bel

7条回答
  •  借酒劲吻你
    2020-12-06 04:38

    SELECT
     @@servername AS 'Server Name' -- The database server's machine name
    ,@@servicename AS 'Instance Name' -- e.g.: MSSQLSERVER
    ,DB_NAME() AS 'Database Name'
    ,HOST_NAME() AS 'Host Name' -- The database client's machine name
    

提交回复
热议问题