其实这个不是问题,直接写更新语句即可,可以参考下面动画演示:
SQL source code:
CREATE TABLE [dbo].[tbl] ( [id] INT, [a] NVARCHAR(10), [b] NVARCHAR(10) ) INSERT INTO [dbo].[tbl] VALUES (1,'123','456') SELECT [id],[a],[b] FROM [dbo].[tbl] UPDATE [dbo].[tbl] SET [a] = [b], [b] = [a] WHERE [id] = 1 SELECT [id],[a],[b] FROM [dbo].[tbl]
明白为什么可以这样,应该先明白SQL的更新时,会先把更新所有行的每一列原始值放在一个deleted表中,更新的值会放在一个 inserted表中。