多租户:如何删除租户? [英] Multi-tenancy: How do I delete a tenant?

查看:92
本文介绍了多租户:如何删除租户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个共享多租户的系统,这意味着每个表都包含所有带有TenantId列的租户的数据,以区分它们.

I have a system with shared multitenancy, which means each table contains data for all tenants with a TenantId column to distinguish between them.

提供新的租户非常简单快捷,但是现在我面临着删除单个租户的挑战.

Provisioning a new tenant is quick and easy, however now I'm facing a challenge with deleting a single tenant.

鉴于实体之间相互依赖,以确保一致性,当系统被其他租户使用时,如何轻松地从数据库中删除租户?

Given that entities depend on each other for consistency, how do I delete a tenant easily from my database, while the system is in use by other tenants?

如果有帮助,系统将使用SQL Server 2008 R2.

The system uses SQL Server 2008 R2, if that helps.

推荐答案

如果我正确,这是将 FOREIGN KEYS ON CASCADE 一起使用的经典案例选项.您只需从主租户表中删除一条记录,由于FKey链正确,系统将删除相关记录或使用 NULL DEFAULT

If I got you right - this is the classical case for use of FOREIGN KEYS with ON CASCADE option. You only delete one record from master tenants table and due to proper chain of FKeys the system deletes related records or updates the reference columns with NULL or DEFAULT value

有时在表中使用DELETE ON CASCADE引用自身的情况下

Sometimes will not work in cases where table references itself with DELETE ON CASCADE

这篇关于多租户:如何删除租户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆