如果没有定义主键,如何删除表中的行 [英] How to delete rows in a table when no primary key is defined

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

问题描述

您好,


我想在没有主键的情况下删除表中的重复行

定义。

For例如:如果我们有table1,数据如下,


Suma 23 100

Suma 23 100


我想从这个表中删除一行并只保留一行。


我尝试删除自联接和存在运算符。但是这两行都删除了

。我想保留一行。


有人可以帮帮我吗。


提前致谢,

Suma


-

发布时使用 http://www.dbforumz.com 界面,应作者的要求

单独检查物品是否符合usenet标准

主题网址:< a rel =nofollowhref =http://www.dbforumz.com/General-Discussions-delete-rows-table-primary-key-defined-ftopict221110.html\"target =_ blank> http:// www .dbforumz.com / General-Disc ... ict221110.html

访问主题网址以联系作者(reg.req''d)。举报滥用行为: http://www.dbforumz.com/eform.php ?p = 760520

Hello,

I want to delete duplicate rows in a table when no primary key is
defined.
For eg: If we have table1 with data as below,

Suma 23 100
Suma 23 100

I want to delete a row from this table and retain only one row.

I tried deleting self joins and exists operator. But it is deleting
both the rows. I want to retain one row.

Can anybody help me out.

Thanks in advance,
Suma

--
Posted using the http://www.dbforumz.com interface, at author''s request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbforumz.com/General-Disc...ict221110.html
Visit Topic URL to contact author (reg. req''d). Report abuse: http://www.dbforumz.com/eform.php?p=760520

推荐答案

向表中添加标识列并删除具有de min值的行。

Add a identity column to the table and delete the row with de min value.


Patarroxa写道:
Patarroxa wrote:
将一个标识列添加到表中并删除具有de min
值的行。
Add a identity column to the table and delete the row with de min
value.




或者用SELECT DISTINCT将数据复制到另一个表中,删除

原始文件并重命名新表格。


robert



Or copy the data with a SELECT DISTINCT into another table, drop the
original and rename the new table.

robert


创建一个新表(带一个键),然后使用SELECT DISTINCT或GROUP BY来支持
填充它来自旧的。


-

David Portas

SQL Server MVP

-
Create a new table (with a key), then use SELECT DISTINCT or GROUP BY to
populate it from the old one.

--
David Portas
SQL Server MVP
--


这篇关于如果没有定义主键,如何删除表中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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