如何查找数据库中的重复记录?我的程序错在哪里?

sky2000 2000-02-18 10:44:00

如何查找数据库中重复记录? 例如有一数据库,内有商品编号(usercode)、名称(fullname)、分级数(SOUNNUM)、删除标志(DEL)等几个字段, 现在我发现里面有许多
商品编号重复, 用什么方法能快速的将它们查找出来?
我自己试着编了一段小程序, 可是不起作用,不知是什么原因, 请指点,谢谢!

**************************************************************************************************
* 查找商品数据库中商品编号重复的记录
*
* 2000.02.18
*************************************************************************************************
set talk on
set exac off
set prin to d:\fox\aa.txt

use d:\fox\ptype.dbf
*这个是源数据库*
inde on usercode to d:\fox\pu uniq FOR USERCODE<>" " .AND. DEL<>"*" .and. sonnum=0
*我想将其作按编号作唯一性索引*
set inde to d:\fox\pu
copy to d:\fox\pu.dbf
use d:\fox\ptype.dbf
inde on usercode to py FOR USERCODE<>" " .AND. DEL<>"*" .and. sonnum=0
*这个数据库的记录远大于上面那个PU.DBf
set inde to py
copy to d:\fox\py.dbf
clos all

SELE 1
USE d:\fox\PU
INDE ON FULLNAME TO d:\fox\PU2 FOR DEL<>"*" .and. sonnum=0
SET INDE TO d:\fox\PU2
SELE 2
USE d:\fox\PY
INDE ON FULLNAME TO d:\fox\PY2 FOR DEL<>"*" .and. sonnum=0
set inde to d:\fox\py2
sele 1
go top
do while .not. eof()
stor usercode to aaa
stor fullname to bbb
?bbb
sele 2
repl all usercode with "****" for fullname=bbb

sele 1
skip
endd

*sele 2
*UPDA ON FULLNAME FROM pu REPL USERCODE WITH A->USERCODE
coun FOR USERCODE=" " .and. sonnum=0 .and. del<>"*"
*DISP ALL FULLNAME,USERCODE FOR USERCODE=" " .and. sonnum=0 to prin
CLOS ALL




...全文
151 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
july 2000-02-18
  • 打赏
  • 举报
回复
我只能一嵌入SQL方式给出说明
select usercode,count(*)
from ptype
group by usercode
having count(*) >1

以此方法检索出来的数据可以清楚显示编码多余一个的内容,且提示你共有多少个重复的值

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧