The topic describes the DF012 T-SQL code analysis rule.
Deprecated
The SETUSER statement is deprecated.
The SETUSER statement is deprecated. It is recommended to use the EXECUTE AS clause instead.
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.
SETUSER 'Mary'
SELECT * FROM dbo.Customers
EXECUTE AS user = 'Mary'
SELECT * FROM dbo.Customers