有网友在SKYPE问及,如标题,SQL中 将同一个表中的A列更新到B列,B列更新到A列。
其实这个不是问题,直接写更新语句即可,可以参考下面动画演示: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] = 1SELECT [id],[a],[b] FROM [dbo].[tbl]