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 responses to “Change SQLCMD default editor”

  1. 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. […] 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. […]

  3. 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”?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.