如果数据没有变化,我想更新一个表,在SQL Server中是可能的,但在 MySQL 中我怎么能?
MySQL
DROP TABLE IF EXISTS PEOPLE;
CREAte tempORARY table PEOPLE
(
_data CHAR(1),
id int
);
INSERT into PEOPLE
SELECT 'N',1 UNION ALL
SELECT 'Y',2 UNION ALL
SELECT 'N',3 UNION ALL
SELECT 'Y',4;
-- now I want to update it
UPDATE PEOPLE
SET _data = 'A'
WHERE id = 1;
-- 1 row(s) affected
-- now I want to update it again
UPDATE PEOPLE
SET _data = 'A'
WHERE id = 1;
-- 0 row(s) affected
如果数据没有变化,我想更新数据。
SQL 服务器
DECLARE @tempORARY table
(
_data CHAR(1),
id int
);
INSERT into @tempORARY
SELECT 'N',1 UNION ALL
SELECT 'Y',2 UNION ALL
SELECT 'N',3 UNION ALL
SELECT 'Y',4;
-- now I want to update it
UPDATE @tempORARY
SET _data = 'A'
WHERE id = 1;
-- 1 row(s) affected
-- now I want to update it again
UPDATE @tempORARY
SET _data = 'A'
WHERE id = 1;
-- 1 row(s) affected
我希望我解决了我的问题,如果您仍有疑问,请发表评论。