| Author |
Topic |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2007-10-03 : 14:36:22
|
| Gurus,Why we are calling truncate as a DDL ?ThanksKrishna |
|
|
eyechart
Master Smack Fu Yak Hacker
3575 Posts |
Posted - 2007-10-03 : 14:44:45
|
| maybe because a truncate cannot be rolled back? That is how it is different than a DELETE for example.-ec |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-03 : 14:47:07
|
acctaully a truncate can be rolled back.create table t1 (id int)insert into t1select 1 union allselect 2 union allselect 3select * from t1begin tran truncate table t1rollbackselect * from t1begin tran truncate table t1commitselect * from t1drop table t1 _______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2007-10-03 : 14:47:47
|
| Yes Spirit!!! We can rollback the truncate.Gurus -This is not an interview question.-- Krishna |
 |
|
|
eyechart
Master Smack Fu Yak Hacker
3575 Posts |
Posted - 2007-10-03 : 14:53:10
|
| hmmm, even a drop table statement can be rolled back using the test code spirit posted. This is different behavior than other RDBMS btw. For example, in Oracle you cannot rollback a drop table statement or a truncate table statement.So, I don't know the answer to this question then as it pertains to SQL Server.-ec |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-03 : 14:53:58
|
| the difference is in how it uses the transaction log.with delete a deletion of each row is stored in transaction log while with truncate only page deallocations are stored in tran log._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2007-10-03 : 14:54:35
|
| Yes EC, in Oracle we can't rollback the Truncate. But SQl we can. -- Krishna |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-03 : 14:55:41
|
quote: Originally posted by eyechart hmmm, even a drop table statement can be rolled back using the test code spirit posted. This is different behavior than other RDBMS btw. For example, in Oracle you cannot rollback a drop table statement or a truncate table statement.So, I don't know the answer to this question then as it pertains to SQL Server.-ec
isn't there a kind of a trasaction bucket or something that holds all commited/rollbacked transactions and the user must commit this bucket to the db himself?i thought i read something about this a while ago..._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2007-10-03 : 14:56:38
|
| Spirit, Could you tell me the exact answer please. Still i am searching the answers in google.ThanksKrishna |
 |
|
|
eyechart
Master Smack Fu Yak Hacker
3575 Posts |
Posted - 2007-10-03 : 14:58:31
|
quote: Originally posted by spirit1 the difference is in how it uses the transaction log.with delete a deletion of each row is stored in transaction log while with truncate only page deallocations are stored in tran log.
nice. I just looked this up in Kalen's book and that is exactly what she said. This seems to be a good interview question. -ec |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-03 : 15:00:32
|
| my opinion is that it's ddl because you can't filter modified data with it. you simply remove all the pages in a table from disk. also truncate releases all empty pages from a table._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-03 : 15:02:36
|
| @ec:also note the aquired locks on the table with delete and truncate:delete locks every rowtruncate rows every page/table but not row so fewer locks are used (less memory)_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2007-10-03 : 15:03:31
|
| Sprit,I have a small doubt over here. How about the page status while rollback the truncate statment?ThanksKrishna |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-03 : 15:04:14
|
| what do you mean "page status"?_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2007-10-03 : 15:05:14
|
| pages in a table |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2007-10-03 : 15:09:33
|
| Thanks Spirit and EC-- Krishna |
 |
|
|
eyechart
Master Smack Fu Yak Hacker
3575 Posts |
Posted - 2007-10-03 : 15:14:20
|
| I think we just answered a homework question. oh well...-ec |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-03 : 15:15:54
|
it's ok... we learned something new _______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2007-10-03 : 15:16:44
|
| Maybe EC. But I want to clarify the doubt. If i did a wrong post please forgive me-- Krishna |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-10-03 : 15:17:58
|
| don't worry about it. it good to clear up things like that._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenpSSMS Add-in that does a few things: www.ssmstoolspack.com |
 |
|
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2007-10-03 : 15:18:59
|
| I got something new from you guys.Once again Thanks guys-- krishna |
 |
|
|
Next Page
|