求一删除语句,不写日志,要有条件的删除,非Truncate

求一删除语句,不写日志,要有条件的删除,非Truncate
---------------------------------------------------------------

没有!
即使Truncate,也写日志,只不过是页级日志罢了
---------------------------------------------------------------

不是你看需不需要还原,SQL SERVER才来决定需不需要记录日志的。
SQL SERVER要保证整个系统的稳定性,如果机器在删除记录中,但还没完全删除完毕的时候断电,SQL SERVER是要靠事务日志来恢复状态的。

---------------------------------------------------------------

pls:
Best way to Delete records from the large table is

SET ROWCOUNT 50000 (try any number which your server can handle)
BEGIN TRANSACTION
DELETE FROM WHERE

Issue COMMIT coomand if results are desired.

Repeat the above until you have covered all the records to be deleted.

OR Alternatively use TOP command to with WHERE condition to start deleting records.
---------------------------------------------------------------

我想不出一个直接的方法, SQL SERVER 只提供了DELETE, TRUNCATE和DROP三个语句来删除数据. 间接的方法倒有一个,可以不进入LOG的.

select * into newtable from oldtable where xxxxxx, 把你不要删除的数据放在新表中. select into 是不进入LOG的,只要你把select into/bulk copy 打开.

drop table oldtable, 把不要的数据连表一起删掉.

sp_rename 'oldtable','newtable','object'
---------------------------------------------------------------

把你的数据库恢复模式改为“简单”模式,可以让他少写几条日志
---------------------------------------------------------------

用select into出来的表是没有触发器的。。。
记住DROP前保存触发器
---------------------------------------------------------------

你们都是高手,小弟在此学习!
---------------------------------------------------------------

1.数据库恢复模式改为“简单”模式
2.用bcp将原表需删除数据导出一数据文件a,导出需保留数据到b;
3.设置数据库trunc. log on chkp.为true;
4.bcp a 到另一表;
5.truncate 原表;
6.bcp b到原表;
7.设置数据库trunc. log on chkp.为false.

Published At
Categories with 数据库类
Tagged with
comments powered by Disqus