title: Grant access to INFORMATION_SCHEMA
body: <p>We have a utility that does some SQL magic by reflecting the definition for some views and stored procs. For this to work, the code needs access to various fields in the tables INFORMATION_SCHEMA.ROUTINES, INFORMATION_SCHEMA.VIEWS, etc.</p>
  
  <p>So we wrote a cursor that applies</p>
  
  <pre><code>GRANT VIEW DEFINITION on ' + @Name + ' TO tenant'
  </code></pre>
  
  <p>where tenant is the role that the code executes under, and @Name is a cursor variable for the proc name. This works.</p>
  
  <p>But then someone will inevitably drop/recreate a proc, thus removing the access to that's proc's definition, which causes the magic utility to fail.</p>
  
  <p>So what's the best way to say 'all code executing under the role of "tenant" has full read access to all the INFORMATION_SCHEMA tables?'</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>I tried <code>GRANT VIEW ANY DEFINITION TO tenant</code> and it raises next error:</p>
  
  <blockquote>
    <p>Cannot find the login 'tenant', because it does not exist or you do not have permission.</p>
  </blockquote>
  
  <p>Is this because tenant is a role and not a user, or do I just really not have permissions? I'm logged in as sa.</p>