sql server - How can Tenant database connect to the core database -


i have multi-tenant databases. shared database have tenants config table holds tenants info

each of tenants databases has insertion trigger, inserts new record core database attaching tenant id record.

i need know tenant database insertion came, able set tenant id based on database did process.

is there unique id related each database can depend on ?! ..

if using sql2008 or higher can use either db_id or db_name identify database:

select db_id() "id", db_name() "name" 

if used db_id , want display database name reports can use:

select db_name(3) -- i.e. db_name(db_id()) 

Comments