Can I use Tenancy feature with an External Database Table? I need to create TenantId attribute on each table? I need help.

Hi Saulo Goncalves,

What is your use case? To understand better you want to use or import data, from an external database, into a single tenant or use all data in a multi-tenancy way?


I have a external database with many tables, but I can't flag "Is Multi-Tenant" in table properties.



The "TenantId" attribute I've created manually just for test.


Marco Arede wrote:

Hi Saulo Goncalves,

What is your use case? To understand better you want to use or import data, from an external database, into a single tenant or use all data in a multi-tenancy way?




Short answer: Multi tenancy, on OutSystems, is only supported on tables that were created in Service Studio.

Longer answer: OutSystems implements multi-tenancy in tables by creating automatically a Tenant_ID column in every multi-tenant table and creating a view for each existing tenant. The view performs a query like SELECT * FROM TABLE WHERE Tenant_ID = 20 and queries that are generated by the platform will target the views, instead of the table. The platform can't add the Tenant_ID attribute to an external table, nor create the views.

I suggest you create a Tenant_ID column in your external table and make sure you fill in that value whenever you create a new record and add a WHERE Tenant_ID = @TenantId to every query done to that table.

That's a way to solve this limitation, but a long hard work on working on application with many tables.


João Pedro Abreu wrote:

Short answer: Multi tenancy, on OutSystems, is only supported on tables that were created in Service Studio.

Longer answer: OutSystems implements multi-tenancy in tables by creating automatically a Tenant_ID column in every multi-tenant table and creating a view for each existing tenant. The view performs a query like SELECT * FROM TABLE WHERE Tenant_ID = 20 and queries that are generated by the platform will target the views, instead of the table. The platform can't add the Tenant_ID attribute to an external table, nor create the views.

I suggest you create a Tenant_ID column in your external table and make sure you fill in that value whenever you create a new record and add a WHERE Tenant_ID = @TenantId to every query done to that table.