在表SQL中查找重复的行 [英] Find duplicate row in table SQL

查看:108
本文介绍了在表SQL中查找重复的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个带有列(id,名称,地址,城市,密码)的表.
将数据插入表中时,我需要检查重复记录.
例如,如果所有记录名称,地址,城市和密码都相同,则不要插入
否则在表中插入数据.表中的数据非常庞大,我需要快速的性能.
请提出最佳方法.

谢谢

Hi,

I have one table a with column(id,name,address,city,pincode).
while inserting data into table I need to check for duplicate record.
For example if all record name,address,city and pincode is same then dont insert
else insert data in table. Table have very huge data and I need fast performance.
Please suggest best way to do this.

Thanks

推荐答案

这可能有帮助:

http://blog.sqlauthority.com/2007/03/01 /sql-server-delete-duplicate-records-rows/ [ http://archive.msdn.microsoft.com/SQLExamples/Wiki/View.aspx? title = DuplicateRows [ ^ ]
this might help:

http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/[^]

http://archive.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=DuplicateRows[^]


如果您使用的是sql server,则可以创建如下存储过程:


如果存在(从表1中选择名称,则名称= @名称和地址= @地址和城市= @城市和密码= @密码)

开始

SET @ReturnVal =''已经存在!''

--Return @ReturnVal

END

ELSE

开始

-在这里执行插入查询
结束
结束尝试
if you are using sql server , then you can create a stored procedure like this:


IF EXISTS (SELECT Name From table1 WHERE Name =@Name and address=@address and city=@city and pincode=@pincode)

BEGIN

SET @ReturnVal =''Already Exists!''

--Return @ReturnVal

END

ELSE

BEGIN

--here execute insert query
End
end try


这篇关于在表SQL中查找重复的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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