title: How to get the list of all database users
body: <p>I am going to get the list of all users, including Windows users and 'sa', who have access to a particular database in MS SQL Server.
  Basically, I would like the list to look like as what is shown in <code>SQL Server Management Studio</code> (i.e. the list that is shown when you expand <code>[databse] -&gt; Security -&gt; Users</code>) with one important exception: I do not want to see the <code>'dbo'</code> in the list. Rather, I would like to see the actual user who owns the database. So, for example, if 'sa' is the <code>'dbo'</code>, <code>'sa'</code> must be included in the list instead of <code>'dbo'</code>. Another note not to be missed is, the list in the <code>SQL Server Management Studio</code> normally shows Windows users in addition to SQL users, And I would like those users to be included as well.</p>
  
  <p>So far, I have been able to come up with the following query:</p>
  
  <pre><code>SELECT * FROM sys.database_principals where (type='S' or type = 'U')
  </code></pre>
  
  <p>This query is almost right but the problem is it doesn't satisfy the <code>'dbo'</code> condition. </p>
  
  <p>How can I change this query or should I use another one?</p>