Open an Editor (SQL Server Management Studio)
Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics Analytics Platform System (PDW)
This topic describes how to open the Database Engine Query, MDX, DMX, or XML/A editors in SQL Server Management Studio. When opened, each editor window appears as a tab in the central pane of Management Studio.
Before You Begin
Management Studio supports four editors: the Database Engine Query Editor for editing Transact-SQL scripts, the DMX and MDX editors for editing scripts using those languages, and the XML/A editor for editing XML/A scripts or XML files. Any of the editors can also be used to edit text files.
Limitations and Restrictions
If you share files with users at other sites that use distinct code pages, you should save your file with the appropriate Unicode code page to prevent errors when reading the file. Also, when saving files for UNIX or Macintosh, be sure to save your files with the appropriate document format. On the File menu, click Save As, Save with Encoding from the down arrow next to the Save button, and then choose Unix or Macintosh under Line Endings.
Permissions
Operations you perform in a code editor are subject to the permissions granted to the authentication account you used to log in. For example, if you open a Database Engine Query Editor window using Windows Authentication, you cannot execute Transact-SQL statements that reference objects your Windows login account does not have permissions to access.
How to: Open Editors
This section explains how to open the various editors in SQL Server Management Studio.
Using the File/New Menu
On the File menu, click New, and then select one of the query editor options:
Query with Current Connection -Opens a new editor window of the type associated with the current connection in Management Studio. The editor window uses the same authentication information as the current connection. For example, if you select an instance of the Database Engine in Object Explorer, and then use Query with Current Connection, Management Studio opens a Database Engine Query Editor connected to the same instance using the same authentication information.
Database Engine Query - Opens a new Database Engine Query Editor and a dialog to get the information required to connect to an instance of the Database Engine.
Analysis Services MDX Query - Opens a new Analysis Services MDX Query Editor and a dialog to get the information required to connect to an instance of Analysis Services.
Analysis Services DMX Query - Opens a new Analysis Services DMX Query Editor and a dialog to get the information required to connect to an instance of Analysis Services.
Analysis Services XML/A Query - Opens a new Analysis Services XML/A Query Editor and a dialog to get the information required to connect to an instance of Analysis Services.
Using the File/Open Menu
On the File menu, click Open, and then navigate to a file and open it. Management Studio opens the appropriate type of editor for the file extension, copies the contents of the file into the editor window, and also opens a connection dialog if needed. For example, if you open a file with a .sql extension, Management Studio opens a Database Engine Query Editor window, copies in the contents of the .sql file, and opens a connection dialog. If you open a file with an extension not associated with a specific editor, Management Studio opens a text editor window and copies in the contents of the file.
For more information, see Associate File Extensions to a Code Editor.
Using the Toolbar
On the Standard toolbar, click one of the following buttons:
New Query - -Opens a new editor window of the type associated with the current connection in Management Studio. The editor window uses the same authentication information as the current connection. For example, if you select an instance of the Database Engine in Object Explorer, and then click the New Query button, Management Studio opens a Database Engine Query Editor connected to the same instance using the same authentication information.
Database Engine Query - Opens a new Database Engine Query Editor and a dialog to get the information required to connect to an instance of the Database Engine.
Analysis Services MDX Query - Opens a new Analysis Services MDX Query Editor and a dialog to get the information required to connect to an instance of Analysis Services.
Analysis Services DMX Query - Opens a new Analysis Services DMX Query Editor and a dialog to get the information required to connect to an instance of Analysis Services.
Analysis Services XML/A Query - Opens a new Analysis Services XML/A Query Editor and a dialog to get the information required to connect to an instance of Analysis Services.
Using Object Explorer
From Object Explorer:
Right-click the server node connected to an instance of the Database Engine, then select New Query. This will open a Database Engine Query Editor window connected to the same instance of the Database Engine and set the database context of the window to the default database for the login.
Right-click a database node, and then select New Query. This will open a Database Engine Query Editor window connected to the same instance of the Database Engine and set the database context of the window to the same database.
Using Solution Explorer
From Solution Explorer, expand a folder, right-click an item within the folder, and then click Open or double-click the item or file.
Using Template Browser to Open the Database Engine Query Editor
On the View menu, click Template Explorer.
The Template Browser window appears in the right pane.
Double-click a template to open a Database Engine Query window with the text of the template. For example, to open a CREATE DATABASE template, open the SQL Server Templates folder, open the Databases folder, and double-click create database.