DF012: The SETUSER statement is deprecated.
Last modified: May 28, 2025
The topic describes the DF012 T-SQL code analysis rule.
Category
DEPRECATED
Message
The SETUSER statement is deprecated.
Description
The SETUSER statement is deprecated. It is recommended to use the EXECUTE AS clause instead.
Additional information
The EXECUTE AS clause provides more granular control over execution permissions and is the preferred method for specifying the security context for stored procedures, functions, or triggers. Migrating from SETUSER to EXECUTE AS ensures compatibility with future versions of SQL Server and aligns with best practices for managing security within database systems.
Noncompliant code example
SETUSER 'Mary'
SELECT * FROM dbo.Customers
Compliant solution
EXECUTE AS user = 'Mary'
SELECT * FROM dbo.Customers
Was this page helpful?