SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Truncate All Tables
 New Topic  Reply to Topic
 Printer Friendly
Previous Page
Author Previous Topic Topic Next Topic
Page: of 2

Kristen
Test

United Kingdom
22498 Posts

Posted - 01/15/2014 :  04:02:31  Show Profile  Reply with Quote
quote:
Originally posted by LZ

These scripts working well if table names without spaces.


Put square brackets around any objects in SQL that is executed using QUOTENAME, e.g. change

Exec('Truncate table '+@tableName)
...
Exec('Delete from '+@tableName)

to

Exec('Truncate table QUOTENAME('+@tableName + ')')
...
Exec('Delete from QUOTENAME('+@tableName + ')')


Edited by - Kristen on 01/15/2014 04:55:53
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22828 Posts

Posted - 01/27/2014 :  01:34:17  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
or you can use square braces.

Exec('Truncate table '[+@tableName + ']')

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

United Kingdom
22498 Posts

Posted - 01/30/2014 :  13:22:15  Show Profile  Reply with Quote
quote:
Originally posted by madhivanan

or you can use square braces.

Exec('Truncate table '[+@tableName + ']')



I think that's going to cause some grief (which QUOTENAME() avoids) if the table name contains square brackets (although that would be a reason to have a public execution I reckon!)
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22828 Posts

Posted - 02/03/2014 :  06:07:31  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by Kristen

quote:
Originally posted by madhivanan

or you can use square braces.

Exec('Truncate table '[+@tableName + ']')



I think that's going to cause some grief (which QUOTENAME() avoids) if the table name contains square brackets (although that would be a reason to have a public execution I reckon!)


True

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

johnag
Starting Member

South Africa
1 Posts

Posted - 01/03/2015 :  07:46:40  Show Profile  Reply with Quote
A topic that is almost 8 years old. I have just downloaded the original script by Madhivanan (updated I understand). It still works and is great. I use it in development to clear all the tables in a test DB to start a new series of tests. When the project is ready to deploy I make a final clearance of the tables, backup the empty database and ship it with my new system. So simple, all required procedures are included, foreign keys set up etc. Absolute magic. Thanks Madhivanan.
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22828 Posts

Posted - 01/03/2015 :  11:43:19  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by johnag

A topic that is almost 8 years old. I have just downloaded the original script by Madhivanan (updated I understand). It still works and is great. I use it in development to clear all the tables in a test DB to start a new series of tests. When the project is ready to deploy I make a final clearance of the tables, backup the empty database and ship it with my new system. So simple, all required procedures are included, foreign keys set up etc. Absolute magic. Thanks Madhivanan.


Thanks johnag for your feedback

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Previous Page
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000