1.
删除表的重复记录
如果记录完全相同才算重复记录
,
那么
: (sql server2000
下测试通过
)
select distinct * into #tmpp from person
delete from person
insert into person select * from #tmpp
drop table #tmpp
如果有
id
主键
(
数字
,
自增
1
的那种
),
那么
:(sql server2000
下测试通过
)
delete from person where id not in
(select id=min(id) from person group by UserName)
2.复制表(并且复制记录)
select * into persontwo from person(只复制表结构)
insert into persontwo select UserName,Address,Content from person(插入记录)
3.获取表中最小未使用的ID
SELECT (CASE WHEN EXISTS(SELECT * FROM person b WHERE b.Id = 1) THEN MIN(Id) + 1 ELSE 1 END) as Id
FROM person
WHERE NOT Id IN (SELECT a.Id - 1 FROM person a)
4.delete from tablea & truncate table tablea的区别
truncate语句执行速度快,占资源少,并且只记录页删除的日志;
delete对每条记录的删除均需要记录日志
posted on 2006-11-23 09:08
周锐 阅读(294)
评论(0) 编辑 收藏 所属分类:
MySQL 、
Oracle 、
SQL Server