我不知道除了删除所有内容并插入新内容外,还有什么更好的方法来进行此更新?
您不必删除所有开始的行。
您只能删除不再适用的行,而只能插入新的行。或者,您可以使用不再适用的值来更新不再适用的值。
所以要从中得到
Name Role--John AdminJohn MemberJohn Superuser
对此
Name Role--John MemberJohn Junior
您可以删除不再适用的内容。。。
delete from userinroleswhere Name = 'John' and (Role = 'Admin' or Role = 'Superuser');
并插入适用的内容。
insert into userinroles (Name, Role)values ('John', 'Junior');或者,您可以使用新值更新值。
delete from userinroleswhere Name = 'John' and Role = 'Admin';
其次是
update userinrolesset Role = 'Junior'where 'Name' = 'John' and Role = 'Superuser';
你说
如果由于某种原因更新失败(例如,互联网连接丢失)怎么办?
那就是交易的目的。单个SQL事务中的多个语句全部或全部都不成功-要么全部成功,要么不进行任何更改。



