sql server - Schema based multitenancy with SQLServer and Hibernate -


i interested @ implementing multitenancy solution using hibernate provider , sqlserver database. using schema based approach meaning 1 database , different schemas.

specifically, question how alter execution schema sqlserver. have used approach mysql use $database, postgresql set search_path $schema , oracle alter session set current_schema = $schema , able switch 1 schema other, noting schema concept differs 1 database another.

however, sqlserver, understand there's no such thing altering execution schema. aware of possibility of switching default schema of given user in case user not granted sysadmin role. aware of impersonation concept using folllwing query : execute user = $user. impersonation allows 1 user impersonate other user, gives possibility change current user.

switching current user allows definition switch execution schema since once user changed execution schema new user's default schema. however, impersonation has limitation since can't perform impersonation on 32 times.although it's possible execute revert after each impersonation in order avoid reaching limit impersonation number, solution not suitable in case , i'm looking alternative.

does have suggestions multitenancy implementation using sqlserver , schema based approach?

also there solutions other ones mentioned switch execution schema.

your appreciated.thank much.

the following points consideration

  1. the sql server differentiates schema's prefix in tables [dbo].[users] , [tenant01].[users]
  2. since have not mentioned way in resolve database connections each schema in sql server, suggest can take @ azure shard map supports use-case or build own in case pickup connection string centralized store based on tenant context established. ex: tenant01 mapped connectionstring c01 have same database different userid , password. approach 1 more commonly followed. can opt azure shard map mapping behind scenes you.
  3. in case, when provision schema, create sql user or map azure ad user schema , grant necessary permissions on schema. ensures access fine.

the above option of persisting tenant-wise connection strings in store helpful in case plan scale out specific tenant shared db due considerable volume of data growth offer higher response times , better performance rest of tenants.

more on azure shard map

edit

actually, when have user mapped schema in sql server, don't need use [schema].[table] in query, instead can directly use [table], access happens automatically. can map user schema using likealter user erpadmin default_schema = erpadmin; on, queries not require schema prefix table. more details here

hth


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -