Thursday, August 24, 2006

Microsoft SQL Server: how to run a script from within oSQL

I like to use oSQL to do a lot of my work in SQL Server. I'm used to using SQL*Plus in Oracle, so I'm comfortable with the command line. Also, it reassures me to know that I can do my job even if I only have a command line to work with.

There are a few things I liked about SQL*Plus that I had not found in oSQL until recently. One was the ability to run a script from within an oSQL session. You do this with the :r command:

c:>osql -S myserver -d mydb -E
1>:r my_script.sql
2> go
... The script runs ...
1> exit

You could have run this all from the command-line one time through like this:

c:> osql -S my_server -d my_db -E -n -i my_script.sql

However, the :r command lets you read in scripts within an already open session.

No comments:

Post a Comment

I moderate comments blog posts over 14 days old. This keeps a lot of spam away. I generally am all right about moderating. Thanks for understanding.