Incorrect syntax near 'something' in SQL 2005 while doing a 'CREATE USER' or 'CREATE LOGIN'

Annoying little problem and the simple fix

I was entering the following into my SQL Server Management Express window:
CREATE LOGIN 160thUser
  WITH PASSWORD = 'some_password';
USE name_of_db_to_use;
CREATE USER 160thUser FOR LOGIN 160thUser;

And I kept getting the error:
Incorrect syntax near '160'

Now I often use the same LOGIN and USER, so that was not the problem. What I found it out to be is that SQL 2005 does not allow LOGIN and USER obejcts to start with a number... sooo I just flipped them around to:
CREATE LOGIN User160th
  WITH PASSWORD = 'some_password';
USE name_of_db_to_use;
CREATE USER User160th FOR LOGIN User160th;

And everything worked.

Add comment

Loading