When a new database is created database_service_objectives table isn't updated with the new row for that DB

KALAHASTI N MaheshKumar 0 Reputation points
2025-01-08T10:46:19.2966667+00:00

We are resetting the data in database by deleting the existing database and creating a new database with the same name. However database_service_objectives table isn't creating a new row with the latest database_id. the previous database_id is still shown. Is this some issue with the tables?image


Azure SQL Database
{count} votes

2 answers

Sort by: Most helpful
  1. Sai Raghunadh M 1,760 Reputation points Microsoft Vendor
    2025-01-08T12:08:30.53+00:00

    Hi @ KALAHASTI N MaheshKumar

    Thanks for the question and using MS Q&A platform.

    As per my understanding, your database_service_objectives table isn't creating a new row with the latest database_id and there are no issues with the tables.

    Here are some possible reasons:

    database_id in sys.databases and sys.database_service_objectives represents a global identifier that is unique within the logical server.

    User's image DB_ID may only be used to return the database identifier of the current database in Azure SQL Database. NULL is returned if the specified database name is other than the current database.

    If the caller of DB_ID does not own a specific non-master or non-tempdb database, ALTER ANY DATABASE or VIEW ANY DATABASE server-level permissions at minimum are required to see the corresponding DB_ID row. For the master database, DB_ID needs CREATE DATABASE permission at minimum. The database to which the caller connects will always appear in sys.databases.

    For more information, please refer to these Documentations:

    https://zcusa.951200.xyz/en-us/sql/t-sql/functions/db-id-transact-sql?view=azuresqldb-current#remarks
    https://zcusa.951200.xyz/en-us/sql/relational-databases/system-catalog-views/sys-database-service-objectives-azure-sql-database?view=azuresqldb-current

    I hope, This response will address your query and helped you to overcome on your challenges.

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


  2. RahulRandive 10,066 Reputation points
    2025-01-11T16:17:11.8933333+00:00

    Hi @KALAHASTI N MaheshKumar

    I attempted to reproduce the scenario, and if your goal is to update the database ID for your database, you can try the following steps:

    1. I had a database A with a database ID of 6.
    2. I deleted database A.
    3. I created a test database named Test.
    4. Now I recreated Database A, and it was assigned a new database ID.
    5. Deleted Test database.

    If you want to assign a new database ID to your database, you can follow the steps above. However, I strongly recommend testing this process first in your pre-production environment to ensure it meets your requirements.

    Thank You!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.