TSQL - Update指令加上Top關鍵字
今天在下update指令時突然想到能不能只update最新的一筆(當然,為什麼要這樣跟我的資料表規畫有關係..orz),想了想..瞬間當機..
問了同事之後,總算是reboot了..趕快記起來,免的忘了..
問了同事之後,總算是reboot了..趕快記起來,免的忘了..
UPDATE "表格"
SET "欄位1" = [值1], "欄位2" = [值2]
WHERE ("主索引" IN (SELECT TOP (1) "主索引" FROM "表格" ORDER BY "主索引" DESC))
EX:
UPDATE myTable
SET myFiled = 1
WHERE (PK IN (SELECT TOP (1) PK FROM myTable AS A ORDER BY PK DESC))
留言