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
22415 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
22761 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
22415 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
22761 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
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