删除重复数据的sql方法
表中有一些记录内容重复,也就是说这些记录除了ID不同之外,其他的信息都相同。需要把重复的记录保留一条,剩下的删除
--第一种方法
delete from temp where id not IN (select min(id) from temp group by col1,col2)
--对col1,col2,即要删除的数据col1,col2两个列都相同,删除id大的行
--第二种方法
with a as
(select row_number() over (partition by col1,col2 order by col1,col2) as rid,* from temp
)
delete a where rid>1
--partition by col1,col2 作用如group by col1,col2,即要删除的行col1,col2两个列的数据相同,删除id大的行
相关文档:
在windows2003下面安装SQL Server2000,会提示windows不支持SQL Server2000的版本,安装后,在本机是可以正常使用的,但是无法连接到其他SQL Server2000的服务器,也无法通过其他机器上的SQL Server2000访问,必须安装SQL Server2000sp3或sp4补丁才可以。其实用SQL Server2005就没这么麻烦了。 ......
On BULK COLLECT
By Steven Feuerstein Oracle ACE
Best practices for knowing your LIMIT and kicking %NOTFOUND
I have started using BULK COLLECT whenever I need to fetch large volumes of data. This has caused me some trouble with my DBA, however. He is complaining that although my programs mig ......
1.多where,少having
where用来过滤行,having用来过滤组
2.多union all,少union
union删除了重复的行,因此花费了一些时间
3.多Exists,少in
Exists只检查存在性,性能比in强很多,有些朋友不会用Exists,就举个例子
例,想要得到有电话号码的人的基本信息,table2有冗余信息
select * from table1;--(id,n ......
create PROCEDURE sp_decrypt(@objectName varchar(50))
AS
begin
set nocount on
--CSDN:j9988 copyright:2004.01.05
--V3.1
--破解字节不受限制,适用于SQLSERVER2000存储过程,函数,视图,触发器
--发现有错,请E_MAIL:CSDNj9988@tom.com
begin tran
declare @objectname1 varchar(100),@orgvarbin varbina ......
The following tables describe certain SQL
limits. Adhering to the most restrictive case can help the programmer
design application programs that are easily portable.
Table 7. Identifier Length Limits
Description
Limit in Bytes
Longest authorization
name (can only be single-byte characters) ......