Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3670664
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:23:35+00:00 2026-05-19T02:23:35+00:00

In a multi-tenant application I have a table with TenantId column. This table is

  • 0

In a multi-tenant application I have a table with TenantId column. This table is only accessed using a view which selects rows belonging to a single tenant using TenantId stored in CONTEXT_INFO. Is there a way to have transactions only locking data that this view returns for particular Tenant (ie. lock only rows with the same TenantId)?

It will be a performance loss if I lock the entire table when I’m sure the data being inserted/updated/deleted is never going to collide with those that have a different value in the TenantId column.

That same pattern would apply for any other View which limits some table rows using WHERE clause.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T02:23:35+00:00Added an answer on May 19, 2026 at 2:23 am

    In a multi-tenant deployment the TenantId column must be the leftmost column in every single index, including the clustered index. Corollary is that you cannot have a a heap in multi-tenant applications.

    If you follow this simple rule then, given that every single query must add the TenantId=@currentTenantId predicate, no query will ever ‘wonder’ outside the tenant data slice in any table. This will ensure that there is never contention between two tenants, since each one is interested in only his portion of the index.

    A somehow similar solution can be achieved by using partitioning by TenantId, but given the current 1000 partitions limit and performance degradation inherent in partitioned tables, I would much stronger favor the index key solution.

    There are thing that breaks this ‘status-quo’ like lock escalation (which can be explicitly disabled with ALTER TABLE SET LOCK_ESCALATION) or bulk load table lock (disabled with with sp_tabeloption).

    So, with this knowledge, can we revisit your question and reformulate it as ‘Can we enforce isolation that a tenant can never lock resources owned by a different tenant?’. The answer is yes, as long as you ensure that there are proper tenant specific access paths in every rowset. Which translates to exactly what I say in my first paragraph: add the TenantId as the leftmost key to every index, including all clustered ones, and don’t have any heaps. Small print would follow that solution will work most times, but there will always be specific scenarios in which a tenant can lock resources owned by a different tenant. But to isolate better you’d have to have one db per tenant, which is a nightmare for deployment/maintenance/upgrade.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multi-tenant application and I'm experimenting with using the i18n gem to
I have multi-tenant ASP.NET MVC application which utilizes subdomains to determine the current tenant.
We have an application which is multi-tenant (lots of users all accessing their own
I have a multi-table query, similar to this (simplified version) SELECT columns, count(table2.rev_id) As
We are building an ASP.Net MVC 2 multi-tenant application on SQL Server using the
I currently have heavily multi-threaded server application, and I'm shopping around for a good
I'm currently working on a multi-tenant application that employs Shared DB/Shared Schema approach. IOW,
Given multi-tenant application, How are vendors implementing email notifications from an email account setup
Hi, We are developing a multi-tenant application in Asp.Net with separate Database for each
Let say I have abstract class called: Tenant and Customer. The tenant in this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.