SELECT database_id FROM sys.databases WHERE name = 'YourDB'
How to find database ID while database is in single user mode in sql server
How to find database ID while database is in single user mode in sql server?
in SP_helpdb it will not come then where to search.
2 answers
Sort by: Most helpful
-
Erland Sommarskog 113.6K Reputation points MVP
2023-05-26T21:32:41.99+00:00 -
PercyTang-MSFT 12,501 Reputation points Microsoft Vendor
2023-05-29T01:39:57.4433333+00:00 Hi @ajay gupta
You can try using this function.
select DB_ID() as database_ID
For more information, please refer to the official documentation.
https://learn.microsoft.com/en-us/sql/t-sql/functions/db-id-transact-sql?view=sql-server-ver16
Best regards,
Percy Tang
If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.