首页 > 代码库 > 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)
删除重复的列。
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)
删除重复的列。
sql 语句删除主键、更改主键、删除重复列(多列组合)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。