Connections

Problem: Finding the Server Name

How do I find the server name of the system I am connected to?

Solution: Query the systables Table

Run the following query against the system tables:

SELECT DBSERVERNAME from systables where tabid = 1;

This also demonstrates a method for doing a SELECT for other SQL constants when they are not in a particular table. You can do this by selecting such items as CURRENT or USER in the same manner. The "WHERE tabid = 1" is simply a way of ensuring that you get only one row returned. Another method of doing this is to create a dummy table called "dummy" with only one row and only one column in the table. Then you could

SELECT CURRENT from dummy;

and get the same type of result.

Problem: How many Users are Connected to a Database?

How can I tell how many users and sessions are connected to a particular database environment?

Solution: syssessions and syssqlstat

Run the following SQL command:

DATABASE sysmaster;
SELECT b.sid, b.pid, b.username, a.sqs_dbname, b.tty
FROM syssqlstat a, syssessions b
WHERE a.sqs_sessionid = b.sid
AND a.sqs_dbname = 'your_db_name';

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.22.250