Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sql777
Constraint Violating Yak Guru
314 Posts |
Posted - 2008-02-19 : 13:20:39
|
| Hello,Is there a way I can truncate all tables in my database?Is this something I could do on a hosting account using a shared sql server or I need higher permissions to do this? |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-02-19 : 14:08:36
|
disgruntled employee?One way is to generate the statements then paste the output into a new window and execute it.use <myDatabase>print 'use <myDatabase>'select 'truncate table ' + table_name from information_schema.tables where table_type = 'base table' permission to do this depenends on the permissions granted your "hosting account". Foreign Key constraints on the tables may prevent you from performing TRUNCATEs. If that is the case you can change to DELETES as long as you arrange the tables in the correct order so that child tables are deleted before parent tables.Be One with the OptimizerTG |
 |
|
|
sql777
Constraint Violating Yak Guru
314 Posts |
Posted - 2008-02-19 : 15:51:43
|
| >>disgruntled employee?haha..no! I'm building this web app and I sometimes make a mistake in my DATA init script and I need to truncate all the tables, right now I just create a new db but thats obviously a pain. |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
|
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2008-02-20 : 01:29:58
|
| Hi,Try this alsoSelect 'Truncate Table '+ Name + '' From sys.sysobjects where Type = 'U' |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-25 : 06:27:09
|
quote: Originally posted by ranganath Hi,Try this alsoSelect 'Truncate Table '+ Name + '' From sys.sysobjects where Type = 'U'
That wont work properly. See the link that MVJ postedMadhivananFailing to plan is Planning to fail |
 |
|
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2008-02-25 : 07:54:38
|
quote: Originally posted by ranganath Hi,Try this alsoExec 'Truncate Table '+ Name + '' From sys.sysobjects where Type = 'U'
|
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-25 : 08:39:53
|
quote: Originally posted by ranganath
quote: Originally posted by ranganath Hi,Try this alsoExec 'Truncate Table '+ Name + '' From sys.sysobjects where Type = 'U'
Do you have any specific comment?MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|