You can use a database connection in the Database Explorer view
to create an SQL statement in the SQL editor.
The SQL editor supports any statement that can be run by the database
to which you are connected. If you save the SQL statement, it is stored in
a file with the extension .sql.
Prerequisites: Before you create
an SQL statement by using a database connection:
- Define a database connection in the Database Explorer view.
- If you plan to save the SQL statement, create the project in which to
store the SQL statement.
Restriction: - If you want to reopen the SQL statement in the SQL editor or the SQL builder,
save the statement in a data project. The data project can be a data development
project or a data design project.
- If you save the SQL statement in a data development project, the project
must be associated with a database that contains the database tables that
you use in the statement. Otherwise, you cannot run the statement successfully.
To create an SQL statement in the SQL editor by using a database
connection:
- Open the Data perspective.
- In the Database Explorer view, expand the database connection.
- Right-click the database connection or the database, and then click New
SQL Statement on the pop-up menu.
- In the New SQL Statement window, type a name for the statement.
- Under Edit using, click SQL editor.
- In the Statement template field, select
the template for the type of statement that you want to create. If you do
not want to use a template, select None. If you want
to see sample statements, select Sample statements.
- Click OK. The SQL statement opens
in the SQL editor.
- Complete the SQL statement in the SQL editor, and then save the
statement.
- In the Save As window, select the project in which to save the
SQL statement, and then click OK. If you
select a data development project or a data design
project, the SQL statement is added to the SQL Scripts folder
of the selected project.