Considerations for Offline Editing

You can use the Transact-SQL (T-SQL) editor even if you are offline, that is, not connected to a database. For example, you can still use the editor to edit scripts and queries if you are working remotely, if your database server is down, or if you want to reduce the number of active connections to your database. In addition, when you use the editor to edit the database objects that are defined in your database project, you are working offline. However, not all functionality is available when you are working in an offline (disconnected) state.

Editing Database Scripts and Queries

If you open a session of the T-SQL editor that is not connected to a database, the window title and the property browser indicate that you are disconnected. However, you can still use the editor to create and edit database queries and scripts.

  • To create a query, you open the Data menu, point to T-SQL Editor, and then click New Query Connection. Before the editor opens, the Connect to Database dialog box appears, prompting you for the server and database against which you want to run your script or query. However, you can click Cancel to close the dialog box and use the T-SQL editor when disconnected.

  • To edit a query or a script, you open the File menu, point to Open, and click File. You then specify a .sql file for editing. For example, you can edit scripts that you generated by comparing database schemas.

You must connect to a database server to validate or execute any scripts or queries against databases on that server. If you try to validate or execute a query without connecting to a database server, the Connect to Database dialog box appears. Also, the window title and the property browser might not immediately reflect that you are disconnected from a database if your connection fails unexpectedly (for example, if your server was taken offline). In that case, the Connect to Database dialog box appears the next time that you try to perform an operation that requires a connection.

Editing Database Objects

You can also create and edit the database objects in your database project when you are not connected to a database. However, you typically do not establish a connection to a database to execute the object definitions that are in the form of CREATE or ALTER scripts. To update the database that is running on the server, you must build and deploy any changes that you make to your database project. You can establish a connection and execute those scripts. You might choose to do so when you debug an error in the object definition.

You edit database objects by selecting a database object in your database project, opening the View menu and then clicking Open. When you edit the definition of a database object, you are always editing the offline representation of a database object. If you want to execute the object definition script, you must first establish a connection to a database. The more common way to deploy database object definitions is by deploying your database project.

See Also

Tasks

How to: Modify Database Objects

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

How to: Disconnect from Databases

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

How to: Create a Database Connection

Concepts

Terminology Overview of Database Edition

Other Resources

Script Analysis and Execution in the Transact-SQL Editor

Transact-SQL Editing Essentials