(br************@gmail.com) writes:
That is very weird. I used Management Studio instead of osql, but I
just used your exact commands to create the 'spacy ' login on both
a 2005 and 2000 SQL Server here, and I do get different behavior; 2000
trims the trailing spaces.
I double checked @@version on the 2000 server and it gives me
8.00.2050, which is a post-SP4 hotfix. Since it's a direct create-
login-SYSTEM_USER check, it's not going into any tables I created
either...
I think I have it: on SQL 2000, SYSTEM_USER gives you string actually used
when you logged in. That is, the trailing spaces are included if you
provide them when you log in.
On SQL 2005, SYSTEM_USER gives the name as it stored in system tables, no
matter whether you provided trailing spaces or not when you logged in.
Note that this cuts both ways. You can provide trailing spaces when you
log in, even there are no trailing spaces in your login name, and
SQL Server will let you in. SYSTEM_USER will report those trailing spaces
on SQL 2000, but not on SQL 2005.
Apparently this changes is not documented, but there were a lot of
changes to system tables and security in SQL 2005, so it may not have
been intentional. MS may not have been aware of how it actually worked
in SQL 2000. After all, trailing spaces in login names does not appear
to be a very common thing...
To make this a little more confusing, SQL 2005 adds a new function,
original_login(). This function appears to always trim trailing spaces
(and never add any).
--
Erland Sommarskog, SQL Server MVP,
es****@sommarskog.se
Links for SQL Server Books Online:
SQL 2008:
http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005:
http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000:
http://www.microsoft.com/sql/prodinf...ons/books.mspx