没有主键如何从SQL中的表中删除最后n条记录 [英] Without primary key how to delete last n records from table in SQL

查看:203
本文介绍了没有主键如何从SQL中的表中删除最后n条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当表中没有主键列时,如何从sql中的表中删除最后n条记录。请在此查询中帮助我



我是什么尝试过:



我知道如何用主键删除最后n条记录但没有主键我无法删除。

How to delete last n records from table in sql when there is no primary key column in table.Please help me in this query

What I have tried:

I know how to delete last n records with primary key but without primary key i was not able to delete.

推荐答案

Quote:

假设该表只有3个字段。 FirstName,MiddleName和LastName。并且有1000条记录,我想删除最后10条记录。然后如何删除它们

Suppose the table has Only 3 fields . FirstName, MiddleName and LastName. And there are 1000 records and i want to delete last 10 records. Then how to delete them



然后你必须得到你的最后10条记录声明的决定因素。

如果你没有任何字段可以区分最后一条记录(例如序列号或日期时间),然后你必须找到某种标准。根据你给我们的信息,我能想象的唯一标准是按字母顺序排列。

如果你真的需要删除最后10个插入的记录,那么你应该在表格中包含一个列将作为判别式。

如果您没有这样的列,那么您将只能对文本字段进行排序。如果你在删除前10个记录之前没有对记录进行排序,那么你将删除10个随机记录。

这里重要的是你应该在你的表中有一个能够区分的字段最后10条记录。

希望这会有所帮助。


Then you will have to get a determinant for your "last 10 records" statement.
If you do not have any field than can discriminate the last record (from a sequence number, or a datetime for example), then you have to find some sort of criteria. From the informations you gave us, the only criteria I can imagine is an alphabetical one.
If you really need to delete the "last 10 inserted records", then you should include a column in your table that will serve as a discriminant.
If you do not have such a column, then you will only be able to sort on text fields. And if you do not sort the records before deleting the first 10 of them, then you will delete 10 random records.
Important thing here is you should have a field in your table that will be able to discriminate the "last 10 records".
Hope this helps.


这篇关于没有主键如何从SQL中的表中删除最后n条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆