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”
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
I will have to check out SciTE someday.
[…] 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. […]
[…] In this post, I talked about how you can set your default editor for sqlcmd. […]
[…] 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. […]
[…] 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. […]
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”?
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!