'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. The current value in the column for this table is 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. Everything I found online was about inserting from another table. Any help would be appreciated!
Solution 1:[1]
I think this should work if your table have an autoincrement value as primary key, otherwise you need to specify also the TenantID.
You can't use WHERE in insert, because is a new row.
INSERT INTO Tenant(Address1) values ('5800 Nova Dr')
If you want to update the value of already existing raw you can use
UPDATE Tenant SET Address1 = "5800 Nova Dr" WHERE Address1 like = '5800 Nova Dr'
Solution 2:[2]
UPDATE Tenant SET Address1='5800 Nova Dr' WHERE TenantId='2'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Danilo Cacace |
| Solution 2 | tinazmu |

