SQL Server Performance

Knowledge Sharing: Maximum Length of UserName and password in SQL Server 2005

Discussion in 'SQL Server 2005 General DBA Questions' started by arunyadav, Aug 4, 2009.

  1. arunyadav Member

    Hello Experts,

    Greeting of the day!

    Today one of my collegues asked about the maximum length of a SQL Server USerName and Password. I checked into the system tables/views and found the following:

    A)

    Object Name: sys.sysusers
    Column Name: Name
    Type: sysname
    Length: 256

    Column Name: password
    Type: varbinary
    Length: 256

    B)

    Object Name: sys.syslogins
    Column Name: Name
    Type: sysname
    Length: 256
    Collation: SQL_Latin1_General_CP1_CI_AS

    Column Name: loginname
    Type: sysname
    Length: 256

    Column Name: password
    Type: sysname
    Length: 256

    From this, I concluded that the maximum character length of a SQL Server Username and Password should be 256. Now when I created a login,user and password with 256 characters or more, SQL Server readily accepted it but were trimmed. The final result which I got is:

    Maximum character length of username: 115
    Maximum character length of login: 115
    Maximum character length of password: 128
    Username Accepts: Alphabets, Numeric and special characters
    Login Accepts: Alphabets, Numeric and special characters
    Password Accepts: Alphabets, Numeric and special characters

    Please add your valuable comments.....
  2. Madhivanan Moderator

    Note the datatype. It is sysname. Sysname is functionally same as nvarchar(128).
  3. Madhivanan Moderator

    Also checkdeclare
    @sysname sysname
    set @sysname =REPLICATE('a',256)
    select LEN(@sysname)

Share This Page