如何删除一个表中重复的记录? 、、游标,存储过程的使用
来源:互联网 发布:pe pvdc 知乎 保鲜膜 编辑:程序博客网 时间:2024/06/15 12:32
如何删除一个表中重复的记录? create table a_dist(id int,name varchar(20)) insert into a_dist values(1,'abc') insert into a_dist values(1,'abc') insert into a_dist values(1,'abc') insert into a_dist values(1,'abc') exec up_distinct 'a_dist','id' select * from a_dist create procedure up_distinct(@t_name varchar(30),@f_key varchar(30)) --f_key表示是分组字段﹐即主键字段 as begin declare @max integer,@id varchar(30) ,@sql varchar(7999) ,@type integer select @sql = 'declare cur_rows cursor for select '+@f_key+' ,count(*) from ' +@t_name +' group by ' +@f_key +' having count(*) > 1' exec(@sql) open cur_rows fetch cur_rows into @id,@max while @@fetch_status=0 begin select @max = @max -1 set rowcount @max select @type = xtype from syscolumns where id=object_id(@t_name) and name=@f_key if @type=56 select @sql = 'delete from '+@t_name+' where ' + @f_key+' = '+ @id if @type=167 select @sql = 'delete from '+@t_name+' where ' + @f_key+' = '+''''+ @id +'''' exec(@sql) fetch cur_rows into @id,@max end close cur_rows deallocate cur_rows set rowcount 0 end select * from systypes select * from syscolumns where id = object_id('a_dist')
- 如何删除一个表中重复的记录? 、、游标,存储过程的使用
- 如何删除表中重复的记录?
- SQL脚本--(通用存储过程)如何删除表中某个字段重复的数据
- 如何删除数据表中重复的记录
- 如何删除数据库中重复的记录
- 如何删除数据库中重复的记录
- 如何删除数据库中重复的记录
- 删除表的重复记录(利用游标)
- mysql 使用游标进行删除操作的存储过程
- 一个使用游标的存储过程的实例
- 删除所有的用户表,存储过程,游标的应用,动态SQL的使用
- 如何删除一张表的重复记录
- 如何删除一张表重复的记录?
- 不用游标从表中取出前N条记录的存储过程
- 不用游标从表中取出前N条记录的存储过程
- 在一个存储过程中调用返回一个游标的另一个存储过程
- 存储过程中 游标(CURSOR)的简单使用及其他
- 存储过程中 游标(CURSOR)的简单使用及其他
- Unhandled Exception thrown
- CORBA学习手记3
- oracle存储过程大数据量insert
- Conversion Operators
- svnnotify配置
- 如何删除一个表中重复的记录? 、、游标,存储过程的使用
- 【转】Android JNI 知识简介
- 线程使用
- 实战试用 Android NDK 初见成效
- 【思考】何去何从
- perl正则表达式实现大写字母转小写字母
- 1
- 看书了
- 新的起点