SQL Server "Deny View Any Database To" in stored proc <p>I have a script which generates a database for a given {databaseName}, and then creates a login for a given {loginName} for this database.</p> <p>I then want restrict this user to only be able to view this database, and no others.</p> <p>I have this working through the use of:</p> <pre><code>USE [{DatabaseName}] GO ALTER AUTHORIZATION ON DATABASE::[{DatabaseName}] to [{LoginName}] GO USE [master] GO DENY VIEW ANY DATABASE TO [{LoginName}] GO </code></pre> <p>I have now put this into a stored procedure, but I cannot change to the [master] database to execute the last line:</p> <pre><code>DENY VIEW ANY DATABASE TO [{LoginName}] </code></pre> <p>Is there a way to restrict the user from seeing other database from within a stored procedure?</p> <p>The stored procedure is currently on another database, but I am able to move it.</p>