title: What's the best way to search for a UPC code in a Database?
body: <p>I have a UPC Database of 12-digit UPC-A formatted barcodes (1,900,000 records). Currently they're stored as a varchar(13) due to leading zeros. I am using SQL Server 2008 R2.</p>
  
  <p>I also have an WCF 4.0 API Method that goes and queries the database based on a UPC-A barcodes match. </p>
  
  <ul>
  <li>What's the best way to improve performance of UPC based queries</li>
  <li>What is the best way to store 12-Digit UPC-A Barcodes. Is my assumption to use varchar(12) okay?</li>
  </ul>
  
  <p><strong>Edit: More Information</strong></p>
  
  <p>Products </p>
  
  <ul>
  <li>ProductID <em>(int)</em></li>
  <li>Barcode <em>(varchar(12))</em></li>
  <li>Name <em>(varchar(50))</em></li>
  <li>ImageUrl <em>(varchar(255))</em></li>
  </ul>
  
  <p>My code:</p>
  
  <pre><code>public JsonResult GetProductByCode(string code)
  {
    DBEntities db = new DBEntities;
  
    Product product = (from prod in db.Products
                      where prod.Barcode == code
                      select prod).FirstOrDefault();
  
    return Json( product , JsonRequestBehavior.AllowGet );
  }
  </code></pre>