濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > 數(shù)據(jù)庫(kù)刪除完全重復(fù)和部分關(guān)鍵字段重復(fù)的記錄

數(shù)據(jù)庫(kù)刪除完全重復(fù)和部分關(guān)鍵字段重復(fù)的記錄

熱門(mén)標(biāo)簽:城市地圖標(biāo)志怎么標(biāo)注 美國(guó)地圖標(biāo)注軟件下載 長(zhǎng)沙外呼系統(tǒng)平臺(tái) 西安電話(huà)自動(dòng)外呼系統(tǒng) 電話(huà)機(jī)器人怎么看余額 怎么修改高德地圖標(biāo)注 合肥crm外呼系統(tǒng)加盟 硅基電話(huà)機(jī)器人官網(wǎng) 漯河電銷(xiāo)回?fù)芡夂粝到y(tǒng)
1、第一種重復(fù)很容易解決,不同數(shù)據(jù)庫(kù)環(huán)境下方法相似: 

以下為引用的內(nèi)容:
Mysql 

create table tmp select distinct * from tableName; 

drop table tableName; 

create table tableName select * from tmp; 

drop table tmp; 


SQL Server 

select distinct * into #Tmp from tableName; 

drop table tableName; 

select * into tableName from #Tmp; 

drop table #Tmp; 

Oracle 

create table tmp as select distinct * from tableName; 

drop table tableName; 

create table tableName as select * from tmp; 

drop table tmp; 



發(fā)生這種重復(fù)的原因是由于表設(shè)計(jì)不周而產(chǎn)生的,增加唯一索引列就可以解決此問(wèn)題。 

2、此類(lèi)重復(fù)問(wèn)題通常要求保留重復(fù)記錄中的第一條記錄,操作方法如下。 假設(shè)有重復(fù)的字段為Name,Address,要求得到這兩個(gè)字段唯一的結(jié)果集 

Mysql 

以下為引用的內(nèi)容:
alter table tableName add autoID int auto_increment not null; 

create table tmp select min(autoID) as autoID from tableName group by Name,Address; 

create table tmp2 select tableName.* from tableName,tmp where tableName.autoID = tmp.autoID; 

drop table tableName; 

rename table tmp2 to tableName; 

SQL Server 

select identity(int,1,1) as autoID, * into #Tmp from tableName; 

select min(autoID) as autoID into #Tmp2 from #Tmp group by Name,Address; 

drop table tableName; 

select * into tableName from #Tmp where autoID in(select autoID from #Tmp2); 

drop table #Tmp; 

drop table #Tmp2; 

Oracle 

DELETE FROM tableName t1 WHERE t1.ROWID > (SELECT MIN(t2.ROWID) FROM tableName t2 WHERE t2.Name = t1.Name and t2.Address = t1.Address); 

 


說(shuō)明: 

1. MySQL和SQL Server中最后一個(gè)select得到了Name,Address不重復(fù)的結(jié)果集(多了一個(gè)autoID字段,在大家實(shí)際寫(xiě)時(shí)可以寫(xiě)在select子句中省去此列) 

2. 因?yàn)镸ySQL和SQL Server沒(méi)有提供rowid機(jī)制,所以需要通過(guò)一個(gè)autoID列來(lái)實(shí)現(xiàn)行的唯一性,而利用Oracle的rowid處理就方便多了。而且使用ROWID是最高效的刪除重復(fù)記錄方法。
您可能感興趣的文章:
  • 查找oracle數(shù)據(jù)庫(kù)表中是否存在系統(tǒng)關(guān)鍵字的方法
  • Access數(shù)據(jù)庫(kù)中“所有記錄中均未找到搜索關(guān)鍵字”的解決方法
  • Linux 自動(dòng)備份oracle數(shù)據(jù)庫(kù)詳解
  • 利用SQL Server數(shù)據(jù)庫(kù)郵件服務(wù)實(shí)現(xiàn)監(jiān)控和預(yù)警
  • myeclipse中連接mysql數(shù)據(jù)庫(kù)示例代碼
  • Myeclipse連接mysql數(shù)據(jù)庫(kù)心得體會(huì)
  • MyEclipse連接MySQL數(shù)據(jù)庫(kù)圖文教程
  • python爬取NUS-WIDE數(shù)據(jù)庫(kù)圖片
  • 記一次mariadb數(shù)據(jù)庫(kù)無(wú)法連接
  • 數(shù)據(jù)庫(kù) 關(guān)鍵字一覽表

標(biāo)簽:濟(jì)源 商洛 吉林 廣西 瀘州 玉溪 文山 撫順

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《數(shù)據(jù)庫(kù)刪除完全重復(fù)和部分關(guān)鍵字段重復(fù)的記錄》,本文關(guān)鍵詞  數(shù)據(jù)庫(kù),刪除,完全,重復(fù),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《數(shù)據(jù)庫(kù)刪除完全重復(fù)和部分關(guān)鍵字段重復(fù)的記錄》相關(guān)的同類(lèi)信息!
  • 本頁(yè)收集關(guān)于數(shù)據(jù)庫(kù)刪除完全重復(fù)和部分關(guān)鍵字段重復(fù)的記錄的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    兴城市| 呼玛县| 安图县| 广东省| 聊城市| 嘉兴市| 渭南市| 色达县| 晋城| 贵港市| 凉城县| 盐津县| 连山| 永春县| 湄潭县| 酉阳| 吉安县| 天柱县| 吐鲁番市| 垦利县| 济宁市| 渑池县| 鄱阳县| 华阴市| 奇台县| 堆龙德庆县| 济阳县| 珲春市| 时尚| 河北区| 那坡县| 巴彦淖尔市| 岐山县| 通州市| 德昌县| 抚松县| 内江市| 文安县| 陈巴尔虎旗| 芜湖市| 扬州市|