Search code examples
sql-server-2008access-rights

Change right to user with escape character


I would like to execute the following query :

DENY DELETE ON tableTest to Domain\Username

but it prints

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '\'.

i tried

SELECT @Test = 'Domain\Username'    
DENY DELETE ON tableTest to @Test

but it also didn't work. The Domain\Username is the value i get in sys.database_principals

Any idea?

Thanks


Solution

  • You can use [] to be able to use otherwise invalid characters for identifiers:

    DENY DELETE ON tableTest to [Domain\Username]