title: How does the SETCURRENTKEY() C/AL function in Navision work?
body: <p>I have the following questions:</p>
  
  <ol>
  <li>What does <code>SETCURRENTKEY</code> actually do?</li>
  <li>What is the benefit of <code>SETCURRENTKEY</code>?</li>
  <li>Why would I use <code>SETCURRENTKEY</code>?</li>
  <li>When would I use <code>SETCURRENTKEY</code>?</li>
  <li>What is the advantage of using an index and how do I tie this analogously to the example of an old sorting system of a library?</li>
  <li>What type of database querying efficiency problems does this function solve?</li>
  </ol>
  
  <p>I have been searching all over the internet and the 'IT Pro Developer Help' internal Navision documentation for this poorly documented function and I cannot find a right answer to my questions.</p>
  
  <p>The only thing I know is that <code>SETCURRENTKEY</code> sets the current key for a record variable and it sorts the recordset based on it. When <code>SETCURRENTKEY</code> is used with only a few keys, it can improve query performance. I have no idea what is actually happening when a database uses an index versus not using an index.</p>
  
  <p>Someone told me this is how <code>SETCURRENTKEY</code> works:</p>
  
  <blockquote>
    <p>It is like the old sorting card system in a library: without <code>SETCURRENTKEY</code> you would have to go through each shelf and manually filter out for the book you want. You would find a mix of random books and you would have to say: "No, not this one. Yes, this one". With <code>SETCURRENTKEY</code> you can have an index analogous to the old system where you would just go to a book or music CD based on its 'Author' or 'Artist' etc.</p>
  </blockquote>
  
  <p>That's all fine, but I still can't properly answer my questions.</p>