title: SQL Database Column with Variant Data Type
body: <p>I am writing an application in which users are able to add "inputs" to a form.  These inputs could be of multiple different types including a textbox or checkbox.</p>
  
  <p>In the case of a textbox versus a checkbox, the data types are string versus boolean.</p>
  
  <p><strong>More Information About My Application</strong></p>
  
  <p>1) A user is able to create a "form" that may have multiple different types of inputs for a customer to fill out. Here are some examples. These inputs can be dynamic and are created by the user.</p>
  
  <ul>
  <li>An input that may ask for a users name.</li>
  <li>An input that consists of a checkbox asking if a user wants to be enrolled in a newsletter.</li>
  </ul>
  
  <p>2) The user saves the form, and in the database, based on the type, the newly created input is saved.</p>
  
  <p>3) A new user comes into the application and fills out the new form that was just created.  They fill out the inputs that the original admin created such as their name and they answer yes to enrolling in the newsletter. Then they click submit.</p>
  
  <p>4) The database then saves the answers to inputs.  This is where my problem lies.</p>
  
  <p>My question is how do you store the inputs value in a row in SQL. I have a couple solutions that I will provide but am looking for a consensus on what is typically done in this situation.</p>
  
  <ol>
  <li>Solution #1</li>
  </ol>
  
  <p><strong>Input Name</strong></p>
  
  <p><strong>Input Boolean Value</strong> - (would be NULL when not a boolean type of input)</p>
  
  <p><strong>Input String Value</strong> - (would be NULL when not a string type of input)</p>
  
  <ol start="2">
  <li>Solution #2</li>
  </ol>
  
  <p><strong>Input Name</strong></p>
  
  <p><strong>Input Type</strong></p>
  
  <p><strong>Input Value</strong> (of type string, and i would cast it based on the type)</p>
  
  <ol start="3">
  <li>Solution #3</li>
  </ol>
  
  <p><strong>Input Name</strong></p>
  
  <p><strong>Input Type</strong></p>
  
  <p><strong>Input Value Key</strong> - (weak foreign key to a table depending on the Input Type.  This would not be a real foreign key because it could point to multiple different tables)</p>