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.
Hi @ajay gupta ,
The [Office Open Specifications] tag is dedicated to supporting issues related to open specifications. You can find open specifications here https://learn.microsoft.com/en-us/openspecs/
Since your question does not pertain to one of these specifications, I've removed the [SQL Server Open Specifications] tag and added the [SQL Server] tag. Hopefully, this will help get your post the attention it needs. If I've misunderstood your question and you believe this is related to the Open Specifications documents, please clarify, providing the document name and section with which you have the question or issue.
Escalation Engineer - Microsoft Open Specifications
Sign in to comment
Sort by: Most helpful
Hi @ajay gupta
You can try using this function.
select DB_ID() as database_ID
For more information, please refer to the official documentation.
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.