偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

總結(jié):六種刪除數(shù)據(jù)庫(kù)重復(fù)行的方法

數(shù)據(jù)庫(kù)
SQL Server刪除重復(fù)行是我們最常見的操作之一,下面就為您介紹六種適合不同情況的SQL Server刪除重復(fù)行的方法,供您參考。

SQL Server刪除重復(fù)行是我們最常見的操作之一,下面就為您介紹六種適合不同情況的SQL Server刪除重復(fù)行的方法,供您參考。

1.如果有ID字段,就是具有唯一性的字段

  1. delect   table   where   id   not   in   (      
  2.   
  3. select   max(id)   from   table   group   by   col1,col2,col3...      
  4. )      

group by 子句后跟的字段就是你用來判斷重復(fù)的條件,如只有col1,那么只要col1字段內(nèi)容相同即表示記錄相同。

2. 如果是判斷所有字段也可以這樣

  1. select   *   into   #aa   from   table   group   by   id1,id2,....      
  2. delete   table        
  3. insert   into   table        
  4. select   *   from   #aa  

3. 沒有ID的情況

  1. select   identity(int,1,1)   as   id,*   into   #temp   from   tabel      
  2. delect   #   where   id   not   in   (      
  3. select   max(id)   from   #   group   by   col1,col2,col3...)      
  4. delect   table      
  5. inset   into   table(...)      
  6. select   .....   from   #temp  

4. col1+','+col2+','...col5 聯(lián)合主鍵

  1. select   *   from     table   where   col1+','+col2+','...col5   in   (      
  2. select   max(col1+','+col2+','...col5)   from   table        
  3. where   having   count(*)>1      
  4. group   by   col1,col2,col3,col4        
  5. )   

group by 子句后跟的字段就是你用來判斷重復(fù)的條件,如只有col1,那么只要col1字段內(nèi)容相同即表示記錄相同。

5.

  1. select   identity(int,1,1)   as   id,*   into   #temp   from   tabel      
  2. select   *   from     #temp   where   id   in   (      
  3. select   max(id)   from   #emp   where   having   count(*)>1   group   by   col1,col2,col3...)     

6.

  1. select   distinct   *   into   #temp   from   tablename        
  2. delete   tablename        
  3. go      
  4. insert   tablename   select   *   from   #temp   Sqlclub    
  5. go      
  6. drop   table   #temp  

原文鏈接:http://www.cnblogs.com/zhangshufeng/archive/2011/09/05/2167079.html

【編輯推薦】

  1. 養(yǎng)成一個(gè)SQL好習(xí)慣帶來一筆大財(cái)富
  2. 告訴你,如何成就DBA職業(yè)生涯
  3. SQL Server性能調(diào)優(yōu)之淺析SQL執(zhí)行的過程
  4. 客戶的一次疏忽,DBA的一次噩夢(mèng)
  5. 數(shù)據(jù)庫(kù)點(diǎn)滴之精妙SQL語句

 

 

 

責(zé)任編輯:艾婧 來源: 自 慎的博客
相關(guān)推薦

2010-10-22 16:29:11

SQL Server刪

2011-03-08 08:59:01

SQL Server數(shù)數(shù)據(jù)移動(dòng)

2022-05-25 09:55:40

數(shù)據(jù)重復(fù)提交Java

2011-07-28 16:39:03

MySQL數(shù)據(jù)庫(kù)修改MySQL密碼

2017-10-27 11:47:05

SQL數(shù)據(jù)庫(kù)優(yōu)化

2011-05-24 10:54:15

數(shù)據(jù)庫(kù)重復(fù)數(shù)據(jù)刪除

2011-01-12 21:26:49

2018-04-27 13:00:00

數(shù)據(jù)庫(kù)MySQL刪除重復(fù)行

2023-06-01 16:45:11

React開發(fā)JavaScript

2019-05-06 15:27:48

Oracle數(shù)據(jù)庫(kù)數(shù)據(jù)

2010-04-13 10:15:17

Oracle數(shù)據(jù)庫(kù)

2019-05-16 13:00:18

異步編程JavaScript回調(diào)函數(shù)

2016-09-01 14:04:51

數(shù)據(jù)中心

2010-09-01 16:55:55

SQL刪除連接

2023-09-06 08:00:00

ChatGPT數(shù)據(jù)分析

2023-08-15 15:44:55

React開發(fā)

2011-03-14 15:47:33

Oracle數(shù)據(jù)庫(kù)

2010-10-08 11:13:22

MySQL修改密碼

2020-12-15 10:54:22

物聯(lián)網(wǎng)互聯(lián)網(wǎng)IoT

2023-12-08 08:53:37

數(shù)據(jù)中心人工智能自動(dòng)化
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)