Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The correct answer is <strong>NO</strong>, a stored procedure does not have access to write into a table. However most users perceive it, incorrectly, as YES because of <a href="http://msdn.microsoft.com/en-us/library/ms188676.aspx" rel="nofollow noreferrer">Ownership Chains</a>:</p> <blockquote> <p>When multiple database objects access each other sequentially, the sequence is known as a chain. Although such chains do not independently exist, when SQL Server traverses the links in a chain, SQL Server evaluates permissions on the constituent objects differently than it would if it were accessing the objects separately. These differences have important implications for managing security. Ownership chaining enables managing access to multiple objects, such as multiple tables, by setting permissions on one object, such as a view. </p> </blockquote> <p>So a procedure will be able to write into a table that the user has no permissions to write into <em>if they form an ownership chain</em>. This means that if the owner of the schema that contains the table is the same as the owner of the schema that contains the procedure, an ownership chain is formed and the procedure is allowed to write into the table. Since the vast majority of objects deployed in practice belong to the <code>dbo</code> schema, an ownership chain is almost always formed.</p> <p>It is important to comprehend these details, so you can troubleshoot problems and understand <em>why</em> is the procedure allowed to write into the table. Erland Sommarskog has an excellent comprehensive write up on this topic: <a href="http://www.sommarskog.se/grantperm.html" rel="nofollow noreferrer">Giving Permissions through Stored Procedures</a>. This article goes into great detail explaining all the options available. Your best option, far better than ownership chaining, is <a href="http://www.sommarskog.se/grantperm.html#Certificates" rel="nofollow noreferrer">code signing</a>.</p> <p>Understanding how this works also helps understanding why dynamic SQL seems to 'break': running dynamic SQL is an automatic break in the ownership chain, which causes all 'magic' to disappear. And it also helps understand why this 'magic' appears not to work outside the database: <a href="http://msdn.microsoft.com/en-us/library/ms188694.aspx" rel="nofollow noreferrer">cross db ownership chaining Option</a> default value is 0.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload