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
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.