34,594
社区成员
发帖
与我相关
我的任务
分享
--> 测试数据:[表1]
if object_id('[表1]') is not null
drop table [表1]
create table [表1](
[字段1] varchar(1),
[字段2] varchar(1)
)
go
insert [表1]
select 'a','a' union all
select 'b','a' union all
select 'c','a' union all
select 'd','b' union all
select 'e','a' union all
select 'f','c' union all
select 'g','c'
go
select * from [表1]
/*
字段1 字段2
a a
b a
c a
d b
e a
f c
g c
*/
--truncate用于清空表的记录
truncate table [表1]
select * from [表1]
--表结构存在,记录全部清空
select * into #t from 表名 where 时间>='2011-01-01'
delete from 表名
insert into 表名 select * from #t
如楼上建议 你可以分次删除
select * into #t from 表名 where 时间>='2011-01-01'
truncate 表名
insert into 表名 select * from #t