简体   繁体   English

从SQL Server删除最后一条记录?

[英]Delete last record from SQL Server?

I want to delete the last row from my table which I have 'no' is the auto number. 我想从我的表中删除最后一行,我的自动编号是“ no”。 Could anyone help me please? 有人可以帮我吗?

no | name | sex | phone|
1    Jack    m     343
2     tim    f     233

You may try this 你可以试试这个

DELETE FROM table
WHERE  no = (SELECT Max(no) FROM table)  

Another way of doing it. 另一种方式。

DELETE FROM TableName
WHERE  ColumnName IN (SELECT TOP 1 ColumnName 
                      FROM   TableName
                      ORDER  BY ColumnName DESC);  

Or you can use this with precaution 或者您可以谨慎使用

DELETE FROM TableName
WHERE  ColumnName = Ident_current('TableName')  

Note: This only works if that table has enabled Auto-increment . 注意:仅当该表启用了Auto-increment时 ,此方法才有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM