Reputation: 58
I have a Multi-Tenant databases. The shared database have the tenants config table that holds all the tenants info
each of the tenants databases has an insertion trigger, that inserts a new record to the core database attaching the tenant id to that record.
i need to know from which tenant database the insertion came, to be able to set the tenant id based on the database that did the process.
is there a unique id related to each database that i can depend on ?! ..
Upvotes: 1
Views: 95
Reputation: 16540
If you are using SQL2008 or higher you can use either DB_ID or DB_NAME to identify the database:
SELECT DB_ID() "Id", DB_NAME() "Name"
If you used DB_ID
and want to display the database name for your reports you can use:
SELECT DB_NAME(3) -- i.e. DB_NAME(DB_ID())
Upvotes: 1