简体   繁体   English

插入多租户项目表

[英]Insert into table of multi tenancy project

I need to update(or insert, I dont do a lot of sql work so I dont know which one I really need) some data in our database but its a multi tenant db and I am having trouble specifying which tenant I want to insert into.我需要更新(或插入,我没有做很多 sql 工作,所以我不知道我真正需要哪一个)我们数据库中的一些数据,但它是一个多租户数据库,我无法指定我想插入哪个租户. The current value in the column for this table is NULL .此表列中的当前值为NULL I need to add some data into that column我需要在该列中添加一些数据

I need to do something like:我需要做类似的事情:

INSERT INTO Tenant(Address1) Values('5800 Nova Dr') WHERE TenantId='2'

在此处输入图像描述

Its the "WHERE" part that Azure Data Studio is not liking.它是 Azure Data Studio 不喜欢的“WHERE”部分。 Everything I found online was about inserting from another table.我在网上找到的所有内容都是关于从另一个表插入的。 Any help would be appreciated!任何帮助,将不胜感激!

I think this should work if your table have an autoincrement value as primary key, otherwise you need to specify also the TenantID.我认为如果您的表有一个自动增量值作为主键,这应该可以工作,否则您还需要指定 TenantID。 You can't use WHERE in insert, because is a new row.您不能在插入中使用WHERE ,因为它是一个新行。

INSERT INTO Tenant(Address1) values ('5800 Nova Dr')

If you want to update the value of already existing raw you can use如果你想更新已经存在的 raw 的值,你可以使用

UPDATE Tenant SET Address1 = "5800 Nova Dr" WHERE Address1 like = '5800 Nova Dr'

UPDATE Tenant SET Address1='5800 Nova Dr' WHERE TenantId='2'更新租户 SET Address1='5800 Nova Dr' WHERE TenantId='2'

you can use insert syntax to add a new row if you know the tenantId number如果您知道tenantId 编号,则可以使用插入语法添加新行

INSERT INTO Tenant(TenantId, Address1) Values(2, '5800 Nova Dr');

if the row has not been created or use update syntax if you have already prefilled the table row with null values如果该行尚未创建或使用更新语法如果您已使用 null 值预填充表行

UPDATE Tenant SET Address1='5800 Nova Dr' WHERE TenantId=2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM