Share via


How to: Start the Transact-SQL Editor

You can use the Transact-SQL (T-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. You can access the editor from several locations:

  • The Data menu to create a query.

  • The New Query button on the T-SQL editor toolbar to create a new session with the same connection as the current session.

  • Solution Explorer to modify database objects and scripts within a database project.

  • The Database Unit Testing feature to author unit tests.

  • The Schema Compare feature, by using Export to Editor.

  • The Data Compare feature, by using Export to Editor.

  • When you open any .SQL file in Visual Studio.

    Note

    By default, when you use the T-SQL editor to modify database objects or to author unit tests, you can only edit the objects and tests. You cannot use any of the query execution commands unless you first connect to a database.

The following procedures focus on the first two scenarios: starting the editor from the Data menu and from Solution Explorer. For more information about Database Unit Testing, see Authoring Database Unit Tests. For more information about Schema Compare, see Comparing Database Schemas. For more information about Data Compare, see Comparing Database Data.

To start the T-SQL Editor to create a query

  • On the Data menu, point to T-SQL Editor, and click New Query Connection.

    A T-SQL Editor session opens, from which you can create, validate, run, and save your query.

    For information about how to validate your script or query (you cannot validate a database schema object or a unit test), see How to: Validate a Query without Executing.

    For information about how to run your query, see How to: Execute a Query.

    For information about how to save your query, see How to: Save a Query or Script.

To start the T-SQL Editor to modify a database object or script

  1. In Solution Explorer, click the database object or script that you want to modify.

  2. On the View menu, click Open.

    A T-SQL Editor session opens, from which you can modify, validate, and save your database object or script.

    You can also start the T-SQL editor by right-clicking the object or script that you want to modify and clicking Open or by double-clicking the object or script.

    For information about how to validate your query, see How to: Validate a Query without Executing.

    For information about how to save your query, see How to: Save a Query or Script.

    Note

    The editor behaves differently when you edit database objects. For more information, see Considerations for Offline Editing.

See Also

Tasks

Walkthrough: Create and Execute a Simple Transact-SQL Script

Concepts

Terminology Overview of Database Edition

Other Resources

Managing Database Connections within the Transact-SQL Editor

Script Analysis and Execution in the Transact-SQL Editor