sql 語句刪除主鍵、更改主鍵、重複資料刪除列(多列組合),sql多列

來源:互聯網
上載者:User

sql 語句刪除主鍵、更改主鍵、重複資料刪除列(多列組合),sql多列
--alter table HistoryData drop constraint PK_HistoryData
alter table HistoryData add constraint PK_HistoryData primary key (CollectionTime,Code)
更改主鍵


delete from HistoryData where CollectionTime between'2014-09-01 00:00:00' and '2014-11-01 00:00:00'and ID not in ( 
select id from (
select Code,CollectionTime,max(ID) id from HistoryData 
where CollectionTime between'2014-09-01 00:00:00' and '2014-11-01 00:00:00'group by Code,CollectionTime) a)
重複資料刪除的列。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.