I have three tables roles, users and userRoles , roles contains all the user role information administrator and defaultUser. User Roles tables contains the relationship between user and roles. The issue is I want to change the Ids of roles table. When I try to do it I lose all the user-role records in userRoles table. I want to write a script so that I can read all the userRoles records and update them to new role ids. How can I write this? Is it possible to do something like this
Asked
Active
Viewed 55 times
0
-
1Yes it's possible, but we need more details. Please **[edit]** your question (by clicking on the [edit] link below it) and add some [sample data](https://meta.stackexchange.com/questions/81852) and the expected output based on that data. [Formatted text](https://meta.stackoverflow.com/a/251362) please, [no screen shots](http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question/285557#285557). ([edit] your question - do **not** post code or additional information in comments) – Jan 06 '20 at 07:48
-
Use [ON UPDATE CASCADE](https://stackoverflow.com/questions/1481476/when-to-use-on-update-cascade). – ceving Jan 06 '20 at 08:09
-
@a_horse_with_no_name its a MSSQL database. I will update with some sample data – Kavin404 Jan 06 '20 at 09:05
-
@ceving Its using ef core and there seems to be some anomaly with the migration. Now the userRoles table data gets removed when the migration runs. So I want to update these records before running migration – Kavin404 Jan 06 '20 at 09:07
-
@Kavin404 If it is not a programming problem, you should consider asking on https://dba.stackexchange.com/ – ceving Jan 06 '20 at 10:25