tags:

views:

71

answers:

2

Anytime I use 'script table as' -> 'Insert To' (or other command), the script generated automatically places the database name in the script. Such as:

INSERT INTO [DatabaseName].[dbo].[tblToBeInserted] ...

While not a huge problem to just delete it, it has slipped by a few times and the script breaks if run on a different server with a different database name but has the same schema. (Such as running on [DatabaseName.Test])

Is there an option I can change, or can I modify the output in any way to remove this?

+1  A: 

Assuming that you are using Microsoft SQL Server Management Studio 2005 or higher you can goto the Tools -> Options menu. On the dialog select "Scripting" from the left hand side. On the right-side in the "General Scripting Options" section there is an option called "SCRIPT USE ". You can set that to FALSE.

tchester
I thought that too, but that only applies to the use database statement that is generated with creating/dropping tables. It does not remove it from Select/Insert/Update/Delete to options.
bucha
A: 

In SSMS, go to View -> Template Explorer, you can find a lot of templates there. Or, you can find these template .sql files from %appdata%\Microsoft\Microsoft SQL Server\100\Tools\Shell\Templates\Sql

schrodinger's code
Thanks, I did not know about templates. However, there is a new problem in that the specific templates I'm looking for do not exist in either template explorer, or in the folder location. Am I overlooking the templates?Also, in windows 7 the path is \AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\Templates\Sql
bucha
%AppData% is a windows environment variable, which points to "C:\Users\xxx\AppData\Roaming". So if you type %AppData% in run box (win key + r), it will take you to "C:\Users\xxx\AppData\Roaming". "xxx" means the current windows logon account.
schrodinger's code