How do I find the server name of the system I am connected to?
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.
How can I tell how many users and sessions are connected to a particular database environment?
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';