none
How to set the default query for the SSMS 'New Query' button? RRS feed

  • Question

  • Hi all,

    A simple question, I hope. I have a number of declarations I use in almost every script I use that define variables from the control file in our database (report start and end dates, etc).

    Is there any way to set SSMS to open a default query, rather than a blank query when you click the 'New Query' button in SSMS?

    Thanks in advance
    Sunday, October 4, 2009 11:40 PM

Answers

  • Just to fully answer this question - it's possible to edit the sqlfile.sql file located in:

    (SSMS 2008) C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\SqlWorkbenchProjectItems\Sql
    (SSMS 2005) C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\sqlworkbenchprojectitems\Sql

    Anything you type in this file (will need to be an administrator to edit it) will appear whenever you click "New Query".  

    Wednesday, October 28, 2009 10:23 PM
    Answerer

All replies

  • Sunday, October 4, 2009 11:52 PM
    Moderator
  • ok, done that, but how do I link my 'New Query' button to the template?
    Monday, October 5, 2009 12:12 AM
  • only way I know that you can do that is by using the SSMS tools pack by Mladen

    http://www.ssmstoolspack.com/Features.aspx

    Which is a viable and good solution.  one probably all the DBAs and developers I know use and ahve installed without any problems. 
    Monday, October 5, 2009 12:15 AM
    Moderator
  • You can't do that. I tried it before and couldn't find a solution.
    It defeats the purpose of having a "New Query" button. You can save the code in a folder and once you double click on it it will open a new SSMS window and the script inside it.
    You can aldo default your SSMS to open a New Query windoe on start up, but it will be empty.
    Abdallah, PMP, MCTS
    Monday, October 5, 2009 12:16 AM
  • ok - that's unlikely to work, I assume I will need admin rights on my box to install it.

    thanks anyway
    Monday, October 5, 2009 12:17 AM
  • Abdshall, check the SSMS tools pack.  It's actually handy for adding in default transaction and rollback along with error handling.  I can see a template being loaded for a person that isn't a DBA or developer and just runs some tasks being viable.
    Monday, October 5, 2009 12:18 AM
    Moderator
  • not admin rights but power user.  you install this on the local machine that has ssms installed.  or are you RDPing or something into the server to do this?  if so, I would just have a .sql file with your template and open that which in turn will launch ssms and with that as the query. 

    like Abdshall said :)
    It defeats the purpose of having a "New Query" button. You can save the code in a folder and once you double click on it it will open a new SSMS window and the script inside it.
    Monday, October 5, 2009 12:21 AM
    Moderator
  • Abdshall, check the SSMS tools pack.  It's actually handy for adding in default transaction and rollback along with error handling.  I can see a template being loaded for a person that isn't a DBA or developer and just runs some tasks being viable.
    Thanks, I've seen the tool but never used it, but I mean the functionality he needs is not available by default in SQL Server.


    Abdallah, PMP, MCTS
    Monday, October 5, 2009 12:26 AM
  • no, I'm an analyst with read access to the server, and only a user on my local desktop box. as a result I can't run EXE files to install SSMS tools pack by Mladen.
    Never mind, I'll just put the code in a .SQL file and double click to open.

    Thanks again for your help
    Monday, October 5, 2009 12:27 AM
  • I have this tool installed though I'm not using it yet to its full potential.
    Premature optimization is the root of all evil in programming.

    Donald Knuth, repeating C. A. R. Hoare

    My blog
  • This is how to do it one-time only, during the first launch:

    - create a test file: test.sql in C:\temp
    - create a new shortcut for SSMS: specify

    sqlwb "c:\temp\test.sql"
    or
    ssms "c:\temp\test.sql"

    Use the new shortcut to launch SSMS. You can also specify server name/login info so that it doesn't show the login screen too.

    Thanks,

    Varsham Papikian, New England SQL Server User Group Executive Board, USA
    New England SQL Server User Group; My LinkedIn page
    Please remember to click the "Mark as Answer" button if a post helps you!
    Monday, October 5, 2009 1:48 AM
  • Actually it's possible to do it WITHOUT any third-party tools!
    Don't forget that you CAN customize SSMS/SQLWB (depend if this is SQL Server 2008 or 2005) startup behavior.

    Here is how:

    - create a test file: test.sql in C:\temp
    - create a new shortcut for SSMS: specify

    sqlwb "c:\temp\test.sql"
    or
    ssms "c:\temp\test.sql"

    That's it! Use the new shortcut to launch SSMS. You can also specify server name/login info so it doesn't show the login screen too.

    Thanks,

    Varsham Papikian, New England SQL Server User Group Executive Board, USA
    New England SQL Server User Group; My LinkedIn page
    Please remember to click the "Mark as Answer" button if a post helps you!
    Varsham

    It's basically the same solution I provided. He is trying to customize the behaviour of the "New Query" button which is not possible.

    Abdallah, PMP, MCTS
    Monday, October 5, 2009 1:57 AM
  • Once you've created a template, you can just double click on it from the Template Explorer to open a new query window.  You can think of the Template Explorer as a whole tree full of "New Query" buttons.
    Monday, October 5, 2009 3:10 AM
    Answerer
  • Just to fully answer this question - it's possible to edit the sqlfile.sql file located in:

    (SSMS 2008) C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\SqlWorkbenchProjectItems\Sql
    (SSMS 2005) C:\Program Files\Microsoft SQL Server\90\Tools\Binn\VSShell\Common7\IDE\sqlworkbenchprojectitems\Sql

    Anything you type in this file (will need to be an administrator to edit it) will appear whenever you click "New Query".  

    Wednesday, October 28, 2009 10:23 PM
    Answerer
  • Yes, I installed it and set up a template.
    Premature optimization is the root of all evil in programming.

    Donald Knuth, repeating C. A. R. Hoare

    My blog
  • Is there a local user directory that can be used instead of the install directory?  My company has our computers locked down so that we cannot modify any files under the "Program Files" path.  

    Perhaps something under our user directory?  AppData?

    Wednesday, November 6, 2013 4:00 PM