1.给数据表创建主键
ALTER TABLE dbo.dp_TotalData
ADD
CONSTRAINT tb_PRIMARY
PRIMARY KEY CLUSTERED (PriceID)
2.表中有相同的数据,保留其中的一条,删除其余的数据
select distinct * into #a from 表名 where 条件
delete 表名 where 条件
insert into 表名
select * from #a
drop table #a
删除所有字段内容一致的T-SQL
select distinct * into #Tmp from 表名
drop table 表名
select * into 表名 from #Tmp
drop table #Tmp
3.查询相同的数据
select * from 表名
where 字段名 in (select priceid from 表名 group by 字段名 having count(字段名 ) > 1)
4.如果使用Linq进行数据Update操作,被操作的数据表必须有主键
5.a表和b表中ID字段相对应,把b表中Price字段的值更新到a表中Price字段
update a set a.Price = b.Price from a join b on a.ID = b.aID