All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
ASP.NET,2.0使用user,profile储存信息前,如何部署aspnetdb.mdf和连接_[Asp.Net教程]
在系统中生成Excel流并传给用户_[Asp.Net教程]
LINQ体验(2)——C#,3.0新语言特性和改进(上篇)_[Asp.Net教程]
asp.net函数返回多个值方法_[Asp.Net教程]
扩展GridView控件(九)——给数据行增加右键菜单_[Asp.Net教程]
DataGrid单击一行服务器事件_[Asp.Net教程]
ASP.NET技巧:正则表达式提取数字_[Asp.Net教程]
ASP.NET的Request对象的属性介绍_[Asp.Net教程]
给.Net初学者的一些建议
在asp.net2.0页面部分缓存中使用PartialCachingAttribu
Reading number is top 10 pictures
A man's favorite things14
The sixties of the last century, China is such a kill pig
Seductive beauty of crime1
传奇套装
The money of more than 100 countries and regions15
Is said to be a Chinese female artist fame explicit pictures before1
The little girl with long hair2
Ashlynn Brooke photograph of a group3
Earthquake hedge common sense
2012 national geographic daily picture4
Download software ranking
Sora aoi, the nurse, uniform ,nursing assistant
Boxer Classic video1
Eclipse 4.2.2 For Win32
Boxer vs Yellow1
Tram sex maniac 2 (H) rar bag14
美女写真3
apache-tomcat-6.0.33
Professional killers2 for Android
Boxer's Top ten classic battle7
The Bermuda triangle3
归海一刀 published in(发表于) 2014/2/3 6:36:39 Edit(编辑)
SQL Server中删除重复数据的几个方法_[SQL Server教程]

SQL Server中删除重复数据的几个方法_[SQL Server教程]

SQL Server中删除重复数据的几个方法_[SQL Server教程]


数据库的使用过程中由于程序方面的问题有时候会碰到重复数据,重复数据导致了数据库部分设置不能正确设置……

方法一

declare @max integer,@id integer
declare cur_rows cursor local for select 主字段,count(*) from 表名 group by 主字段 having count(*) > 1
open cur_rows
fetch cur_rows into @id,@max
while @@fetch_status=0
begin
select @max = @max -1
set rowcount @max
delete from 表名 where 主字段 = @id
fetch cur_rows into @id,@max
end
close cur_rows
set rowcount 0


方法二

  有两个意义上的重复记录,一是完全重复的记录,也即所有字段均重复的记录,二是部分关键字段重复的记录,比如Name字段重复,而其他字段不一定重复或都重复可以忽略。

  1、对于第一种重复,比较容易解决,使用

select distinct * from tableName


  就可以得到无重复记录的结果集。

  如果该表需要删除重复的记录(重复记录保留1条),可以按以下方法删除

select distinct * into #Tmp from tableName
drop table tableName
select * into tableName from #Tmp
drop table #Tmp


  发生这种重复的原因是表设计不周产生的,增加唯一索引列即可解决。

  2、这类重复问题通常要求保留重复记录中的第一条记录,操作方法如下

  假设有重复的字段为Name,Address,要求得到这两个字段唯一的结果集

select identity(int,1,1) as autoID, * into #Tmp from tableName
select min(autoID) as autoID into #Tmp2 from #Tmp group by Name,autoID
select * from #Tmp where autoID in(select autoID from #tmp2)


  最后一个select即得到了Name,Address不重复的结果集(但多了一个autoID字段,实际写时可以写在select子句中省去此列)

  查询分析器不能单步调试的的原因

  具体步骤如下:

  1、将服务器【身份验证】属性设置成【混合模式】(window与SQL身份验证)

  2、在【控制面板】中打开【服务】将【MS SQL Server】服务打开【属性】,选择【登录】页面,将登录身份设置成服务器本地帐号和该帐号密码,如administrator,密码123;

  3、重新启动SQL Server服务,此时的服务指的是【SQL服务管理器】中的SQL Server服务;假设【帐号】设置为administrator 。此时达到的效果是:服务器本地帐号administrator与客户端上的administrator(并且该帐号的密码要与服务器密码相同)可以通过【查询分析器】进行调试;如果想让【其他帐号】也能够调试,那么还需要如下设置:
  a、在【服务器】上运行dcomcnfg.exe;

  b、在【默认安全机制】中【默认访问权限】右边点击【编辑默认值】选择允许调试的帐号类型,如users用户类型,sample帐号有包含users组;

  c、重新启动SQL Server服务;

  3、在客户端上创建与服务帐号密码一样的用户,如sample;做到这步就可以通过查询分析器的调试功能进行单步调试了。
  注:第二步更改“启动服务帐户”,在第一次登录之前,必须更改用户密码。不然,event log:以当前密码登录的尝试因下列错误而宣告失败: 在第一次登录之前,必须更改用户密码。






添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.