Find active SQL Server connections for Database

Sometimes we need to check the connection for the database, using the following query we can get the total connection, login Name with Database Name.

Run below script
SELECT DB_NAME(DBID) AS DataBaseName,
COUNT(DBID) AS TotalConnections,
loginame AS LogName
FROM    sys.sysprocesses
GROUP BY DBID, loginame
ORDER BY DB_NAME(DBID)

The result will be shown below.

DataBaseName                 TotalConnections            LogName
-------------------------------------------------
MYTESTDB                          3                                dkadmin
MYDKDB                             119                             dkadmin
MYDKDB                             10                               sa     
master                                17                              sa    
master                                12                              dkadmin
msdb                                  3                                NT SERVICE\SQLSERVERAGENT
                 

PostgreSQL-Query: Sort result set by specific field values using ORDER BY Clause

Problem: Suppose we have a book_inventory table which has some columns such as id, isbn, title, author, publisher, publish_date, etc.. whe...