Home > Back-end >  Insert into table of multi tenancy project
Insert into table of multi tenancy project

Time:02-03

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'

enter image description here

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!

CodePudding user response:

you can use insert syntax to add a new row if you know the tenantId number

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

use update syntax if you have already prefilled the table row with null values

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

CodePudding user response:

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'

CodePudding user response:

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

  •  Tags:  
  • Related