How to: Start the Transact-SQL Editor

You can use the Transact-SQL editor to author and execute database queries, modify database objects and scripts, view scripts that update database schemas or data, and author database unit tests.

A connection to the database server is not required to use the Transact-SQL editor. These procedures focus on how to open a Transact-SQL query window for writing new queries. For more information on how to connect to the database server, see How to: Connect to a Database in the Transact-SQL Editor.

Note

When connected to the database server, each Transact-SQL query window uses a different server connection, even if more than one window is connected to the same server.

You can access the editor from several locations. For new Transact-SQL queries:

  • The Data menu: Click New Query Connection to create a new Transact-SQL query window and prompts you for connection information. Cancel the connection dialog box to work in a disconnected state.

  • The Transact-SQL Editor toolbar: Click the New Query button to create a new Transact-SQL query window.

  • The File menu: Click New File and select Sql File to create a new disconnected Transact-SQL query window.

For existing Transact-SQL queries:

  • The File menu: Click Open File to access a Transact-SQL query window associated with an existing .SQL file.

  • The Solution Explorer: Double-click an existing database object or script within a database project to open a corresponding Transact-SQL query window.

When using Visual Studio Team System:

  • The Database Unit Testing feature: creates a Transact-SQL query window for authoring unit tests.

  • The Schema Compare feature: Click Export to Editor to open a corresponding Transact-SQL query window.

  • The Data Compare feature: Click Export to Editor to open a corresponding Transact-SQL query window.

To start the Transact-SQL Editor with the Data menu

  1. On the Data menu, point to Transact-SQL Editor, and click New Query Connection. This opens the Connect to Server window.

  2. Click Cancel for a disconnected Transact-SQL editing session or enter the connection information to connect to an instance of SQL Server, beginning with version SQL Server 2005. For more information, see How to: Connect to a Database in the Transact-SQL Editor.

To start the Transact-SQL Editor with the Transact-SQL Editor toolbar

  1. On the Transact-SQL Editor toolbar, click New Query. This opens the Connect to Server window.

  2. Click Cancel for a disconnected Transact-SQL editing session or enter the connection information to connect to an instance of SQL Server, beginning with version SQL Server 2005. For more information, see How to: Connect to a Database in the Transact-SQL Editor.

To start the Transact-SQL Editor with the File menu

  1. On the File menu, click New File. This opens the New File window.

  2. Under the General template, select Sql File.

See Also

Tasks

How to: Validate a Query without Executing

How to: Execute a Query

How to: Save a Query or Script

How to: Connect to a Database in the Transact-SQL Editor

How to: Connect to Different Databases in the Same Editor Session

Walkthrough: Create and Execute a Simple Transact-SQL Script

Concepts

Editing Database Scripts and Objects with the Transact-SQL Editor

Other Resources

Verifying Existing Database Code with Unit Tests

Compare and Synchronize Database Schemas

Compare and Synchronize Data in One or More Tables with Data in a Reference Database