作者MugenPower (无限MUGEN)
看板Database
标题Re: [SQL ] 请问删除语法中的truncate和delete 有ꐠ…
时间Thu Aug 30 15:36:21 2007
※ 引述《alexcwtzeng (狂泻不止)》之铭言:
: ※ 引述《ruby0104 (:))》之铭言:
: : delete 跟 truncate 都可以rollback
: : 提外话,这个问题面试的时候 还挺常问的 XD
: Oracle SQL 的说明
: http://psoug.org/reference/truncate.html
: SQL-Server 的说明也很多,说明了 TRUNCATE table 如何 rollback
: ==== Example =====
: USE tempdb
: CREATE TABLE t (c1 INT)
: INSERT INTO t
: SELECT BINARY_CHECKSUM(OrderID) FROM Northwind..Orders
: SELECT * FROM t
: BEGIN TRAN
: TRUNCATE TABLE t
: COMMIT TRAN
: SELECT * FROM t
: INSERT INTO t
: SELECT BINARY_CHECKSUM(OrderID) FROM Northwind..Orders
: BEGIN TRAN
: TRUNCATE TABLE t
: ROLLBACK TRAN
: SELECT * FROM t
: DROP TABLE t
: ==== End Example ====
: 所以在 begin tran ... end tran 的 block 里,所有的东西都可以 rollback。
: 但这是网路文章,我只是引述。SQL-Server 偶不会。
: 但是 Oracle Database 中,truncate table 与 delete table 是很大的不一样滴。
: 在 ANSI/ISO standard 中说明 DDL 是属於 autocommit 的指令。
: 而 truncate 是属於 DDL 的指令。
Oracle Documents : Database Administrator's Guide -
Using the TRUNCATE statement provides a fast, efficient method for deleting
all rows from a table or cluster.
A TRUNCATE statement does not generate any
rollback information and it commits immediately. It is a DDL statement and
cannot be rolled back. A TRUNCATE statement does not affect any structures
associated with the table being truncated (constraints and triggers) or
authorizations. A TRUNCATE statement also specifies whether space currently
allocated for the table is returned to the containing tablespace after
truncation
---------------------
begin tran与 end tran 应该只有 sql server 可以用吧 ?
从 example的 northwind可以看出来是 sql server的 example
sql server 不熟 XDDD 那应该是MS独有的 feature ??? (←不确定)
不过 在什麽情况下 会需要用到 truncate ,然後再rollback?
我想应该有更好的方式
RDBMS几家大厂在标准之外各做各的
哪天连 drop database 也能 rollback
其实也不用太意外 XDDDDDDDD
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 202.145.230.2
※ 编辑: MugenPower 来自: 202.145.230.2 (08/30 15:37)