Change SQLCMD default editor

In SQLCMD, if you type ed, it will invoke a text editor and put the last command you run in the editor buffer. The default editor is Edit, a command line editor of DOS.

This behavior is very similar to Oracle Sql Plus, by the way. The difference is that in Sql Plus, you can use / to run the command after you finished editing, whereas in SQLCMD you still need to type go for it, well, to go;)

Anyway, the really neat thing is you can change the default editor to whatever you like. I know many DBAs / developers have their own preferred editors, like Edit Plus, TextPad, or even plain old Notepad. This is exciting because if you work in your favorite editor, you feel you are in control and your productivity increases. For me, I have changed the default editor to VIM, a clone of VI. VI is my favorite editor.

This is how you do it:
1. Open a DOS prompt;
2. Type set sqlcmdeditor=vim, or notepad or whatever;
3. Go to sqlcmd, enter and execute a sql statement, then type ed;
4. Viola, your editor of choice opens. Edit away, after you are done, save and close;

I am very happy to find this feature. It is a real productivity enhancer.

8 Comments »

  1. Chris Hedgate Said,

    October 26, 2005 @

    Cool! I have not had enough time to get very familiar with SQLCMD, so it is great seeing your tips for it.

    set sqlcmdeditor=SciTE

    Done!
    /Chris

  2. Administrator Said,

    October 27, 2005 @

    I will have to check out SciTE someday.

  3. The Ji Village News » Customize Oracle sqlplus editor Said,

    November 29, 2005 @

    [...] In Oracle sqlplus, if you type ed or edit at the command prompt, sqlplus will put the last command into an editor buffer for easy editing. In Windows, the default editor is Notepad. In Unix / Linux, the default editor is usually vi. I have changed the default sqlplus editor on my Windows machine to vi. In an earlier post, I explained how to change Microsoft SQL Server 2005 sqlcmd default editor. [...]

  4. The Ji Village News » Setting sqlcmd environment variables Said,

    April 17, 2006 @

    [...] In this post, I talked about how you can set your default editor for sqlcmd. [...]

  5. The Ji Village News » No edit in DOS on Windows 64-bit Said,

    April 28, 2006 @

    [...] As described earlier, the default editor for sqlcmd is edit. However, when you invoke it on a 64-bit machine, you get: ‘edit.com’ is not recognized as an internal or external command, operable program or batch file. [...]

  6. The Ji Village News » Using up and down arrow to cycle through sql command Said,

    June 13, 2006 @

    [...] Like osql, if you use up and down arrow, sqlcmd will cycle through sql statements you ran earlier. This can be handy. You can also invoke your editor for command editing, as I discussed here. [...]

  7. ana Said,

    August 15, 2006 @

    this is so interesting! now my question is that “how can i create a sqlplus command that will change the default local editor to Microsoft windows notepad.exe text editor”?

  8. Haidong Ji Said,

    August 15, 2006 @

    Ana,

    I am glad you find it useful. I have a blog entry on that. Please follow the link below:

    http://www.haidongji.com/2005/11/29/customize-oracle-sqlplus-editor/

    Cheers!

RSS feed for comments on this post · TrackBack URI

Leave a Comment