In a Structured Query Language (SQL) database, commands are executed via the use of queries, which are specific instruction sets run against the database for performing a multitude of tasks, such as formatting tables, removing or adding data, and executing stored procedures.
Although creating a custom SQL query requires programming skill and a thorough knowledge of the Structured Query Language, running a query through SQL Server Management Studio is easily accomplished.
First, you will want to log into SQL Server Management Studio either locally on your server, or via remote connection. For the purposes of this article, we will use an example where the user is logging in locally using Windows Authentication.
Next, you will want to select from the list of databases the one which you are running the query against. In this example, we will be running it against the ‘master’ database.
(Please note that this is only an example used for the purposes of this article, and the ‘master’ database should be edited with extreme caution, as it is inexorably tied to all other databases hosted on the server, and contains several vital stored procedures.)
Once the database is selected, click on the button in the upper left-hand corner of the window which says, ‘New Query‘.
A window will then open beside the database list, enabling you to enter your query. Once it has been entered, click the button which says ‘Execute‘ at the top of the window. Management Studio will then run your query against the selected database, and once processed, it will confirm whether or not the query was run successfully.
Try our troubleshooting service
- Microsoft Certified Engineers
- Remote Log-in to Your Servers
- End-to-End Troubleshooting
Our Certified Technicians have been supporting Microsoft® products for well over a decade.
Tell us where you are getting stuck
Having Trouble Implementing This Solution?
Why not let our Microsoft® Certified Engineers do it for you.
Just $50.00 one time fee.
Some queries will be pre-compiled in a file with a ‘.sql’ extension. These are easily run, as well. Essentially, once the window in the above picture is open, double-click the ‘.sql‘ file, and it will automatically open within Management Studio. Once opened, click ‘Execute‘.
Please bear in mind that it is always good practice to back up a database prior to running any type of query against it. For assistance with backing up a database, please see the following Knowledge Base article: