Lesson 19: Query the remote database

In this lesson, you query the remote database and return results to the server. This is very useful when troubleshooting because you can find out exactly what state the remote database is in.

The tables you've added to the database in this tutorial do not contain any data, so instead you'll query the database system tables. Even though you are querying a system table in this example, everything you do works exactly the same way if you queried a user table.

Suppose that you wanted to confirm that the schema change you performed in the last lesson did what you expected, that the product table was created with the correct columns. You could confirm that by querying the systable and systabcol system tables.

 To query the remote database
  1. In the Folders view of Sybase Central under Central Admin Tutorial, right-click Remote Tasks and choose New » Remote Task. The Create Remote Task Wizard appears.

  2. On the Welcome page, type Table Query in the Name field.

  3. Check This Task Requires or Creates a Remote Database and set the Remote Schema Name to Tutorial Application v2.0 and click Next.

  4. On the Trigger Mechanisms page, check When it is Received by an Agent and click Finish.

  5. Add an Execute SQL command to the task with the following SQL:

    select * from systable where table_name = 'product'
    go
    select * from systabcol order by table_id
  6. Right-click the new Table Query task and choose Deploy. Click Next.

  7. For Recipients, choose Specific Agents, select agent AID_JOHN and click Next then Next again.

  8. On the Reporting Results and Status page, set both If Task Succeeds and If Task Fails to Send Results and Status Immediately. Click Finish and wait until the task executes.

  9. Click the deployed copy of the Table Query task in the Folders view and select the Results tab. If you don't see any results on the tab press, F5 to refresh it.

  10. Right-click on the line in the table for the Execute SQL statement and select Details. The Command Result dialog appears.

  11. Pick the Results tab on the dialog. This tab shows results of any queries executed. Press F5 to refresh the results as necessary. The Result dropdown at the top of the pane allows you to switch between results for the two queries.