Running SQL scripts

Creating a SQL Script

There are several methods that can be used to run SQL scripts.  Which method is best, depends on the purpose of the script.

If the script is meant to be run one time, or on rare occasion with no set pattern, then running the script directly makes the most sense.  It can be run through the SQL Management Studio Express, or from the Windows command line, if OSQL is installed.

The easiest way to write your script, is using the SQL Management Studio.  Open Management Studio, and log into the database server.  Expand the databases, and right click on the database that you want to run the script on, and select New Query.  The right hand side will open a new window for you to write your query.

When writing queries in the Management Studio, as you type, table names and field names will show in a drop down list, based on what you are typing.  You can select from these, and save yourself some keystrokes.

Once you have finished your script, and tested it (by using the Execute button in Management Studio Toolbar), save it with a ".sql" extension.  By using this extension, if you double click on the script in Windows, it will automatically launch the SQL Management Studio, and load your script.  Once you log in to the database server, your script is then ready to be run, by hitting the Execute button.

This is simpler than using OSQL to run your scripts.  However, there are some advantages to using OSQL, which I will look at in my next blog.

If you are not current on the SQL language syntax, try the site:  

NOTE:  If you are creating SQL scripts you should be the Administrator or creating scripts with the Administrator approval.  Your SQL Database Server (Engine) should be password protected.  You will need this information to get logged in.

We write SQL scripts for our customers almost on a daily basis.  If you need help contact us at CCS Retail Systems.


Leave a Reply