title: SQL Server - Using tinyint with enum
body: <p>Suppose that I have a SQL Server database that, amongst other tables, has a table named <code>Mail</code>, which has  the expected recipient, sender, message body, etc. associated with it, one of these being the property <code>Priority</code>, which basically indicates if a mail has a high, normal, or low priority of being sent. Since I'll be only using these small amount of values (and if more were to be added it wouldn't be that many), I decided to make Priority a <code>tinyint</code> type, while  in my code I'd represent is an <code>enum</code> type.</p>
  
  <p>My question is, what is the right way to insert and retrieve this property when calling the database? In the case of retrieval (using a <code>DataRow</code>) I have:</p>
  
  <pre><code>mail.Priority = (MailPriority)(byte)row["Priority"];
  </code></pre>
  
  <p>And for inserting:</p>
  
  <pre><code>parameter = new SqlParameter("@Priority", SqlDbType.TinyInt);
  parameter.Value = (byte)mail.Priority;
  statement.Parameters.Add(parameter);
  </code></pre>
  
  <p>(Where statement is a <code>SQLCommand</code>).</p>
  
  <p>So would this work, and is it the right way to do it? I figured that using <code>tinyint</code> would be okay, since the possible values can't be that many, but I don't know if <code>int</code> would be fine, better in terms of performance, or more commonly used, etc.</p>