Using Drag and Drop to Create Queries

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Tutorials > "ZooDB" Database > Querying the Database >

Using Drag and Drop to Create Queries

DatabaseSpy allows you to generate SELECT statements by dragging a table and dropping it into an SQL Editor window. To this aim, you should make sure that the default statement generated for tables is a SELECT statement. Select the menu option Tools | Options, go to the Online Browser page and choose Select as SQL action for tables.

zoo-option-select

 

To generate a query based on the table "tblZookeepers" and specify a target for it:

1.Click the Online Browser tab.
2.Drag and drop the table tblZookeepers to the same SQL Editor window where the file animalType_queries.sql is currently open. This generates the following SELECT statement:

SELECT [ZookID], [FirstName], [LastName], [Address], [City], [State], [Telephone], [DOB] FROM [ZooDB].[dbo].[tblZookeepers];

3.Place the cursor anywhere in the new SELECT statement. Click the Current statement ic_select-entire-stmt icon in the SQL Editor window. This selects the entire statement.
4.Click the Define Target name ic_insert-target-single button in the SQL Script toolbar. The text -- target: Result appears above the statement.

target_result

5.Change the text "Result" to "Select zookeepers".

zoo_target_result_new_name

6.In the Properties window, make sure that either "Semicolons" or "SQL Grammar" is selected in the Group statements for execution with drop-down list.
7.Click the Execute ic_execute-sql button or press F5. The results of all three queries in the script appear in separate result windows.

tab_result-zookeepers

Note:When executing only one of the select statements, make sure that the --target: text is selected in addition to the select statement below it, if you want the target window text to be generated. The Current statement button will not select the --target: line.

© 2019 Altova GmbH