如何从SQLServer中不使用WHERE条件,从表中删除“第一条”记录?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (761)

表中删除“第一条”记录是否可行?SQL Server,不使用任何WHERE条件和不使用CURSOR?

提问于
用户回答回答于
WITH  q AS
        (
        SELECT TOP 1 *
        FROM    mytable
        /* You may want to add ORDER BY here */
        )
DELETE
FROM    q

请注意

DELETE TOP (1)
FROM   mytable
用户回答回答于
-- MYSql:
DELETE FROM table LIMIT 1;
-- Postgres:
DELETE FROM table LIMIT 1;
-- MSSql:
DELETE TOP(1) FROM table;
-- Oracle:
DELETE FROM table WHERE ROWNUM = 1;

扫码关注云+社区

领取腾讯云代金券