Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run sql script using SQL Server Management Studio?

Tags:

sql-server

I have been following this tutorial: http://www.misfitgeek.com/2010/07/adding-asp-net-membership-to-your-own-database/

I have installed SQL Server Management Studio Express from here: http://www.microsoft.com/download/en/details.aspx?id=8961.

1) How can I locate my database?

2) How do I run the SQL script on my database from external file?

like image 737
Anajrob Avatar asked Apr 21 '12 18:04

Anajrob


People also ask

How do I run a SQL script in SQL Server Management Studio?

Click Query > Connection > Connect to connect to the server that contains the database you want to access. Select the appropriate StarTeam Server database. Open the tuning script, by choosing File > Open > foldername\scriptname. Execute the script, by clicking the Execute button on the toolbar or by pressing F5.

How do I open SQL File in SQL Server Management Studio?

You can open a document in one or more editors by clicking Open on the File menu and then clicking File. In the Open File dialog box, select the file, click the Open arrow, and then click Open With. In the Open With dialog box, in the Select a program to open list, click the preferred program, and then click Open.

How do I run a SQL script from a database?

Generate a Script in the SQL Server Management Studio Open SQL Server Management Studio (SSMS) Expand Databases. Select the database to script. Right-click on the database and select Tasks > Generate Scripts.


2 Answers

This website has a concise tutorial on how to use SQL Server Management Studio. As you will see you can open a "Query Window", paste your script and run it. It does not allow you to execute scripts by using the file path. However, you can do this easily by using the command line (cmd.exe):

sqlcmd -S .\SQLExpress -i SqlScript.sql 

Where SqlScript.sql is the script file name located at the current directory. See this Microsoft page for more examples

like image 152
Ulises Avatar answered Sep 21 '22 00:09

Ulises


Open SQL Server Management Studio > File > Open > File > Choose your .sql file (the one that contains your script) > Press Open > the file will be opened within SQL Server Management Studio, Now all what you need to do is to press Execute button.

like image 39
Maryam Avatar answered Sep 23 '22 00:09

Maryam