title: AspNetUserLogins table and maximum size of index keys in SQL Server
body: <p>The schema of the identity model in VS2017/aspnetcore defines a table called AspNetUserLogins table to store external logins (CREATE statement below). It defines the primary key as a composite of [LoginProvider]  [nvarchar] (450) and [ProviderKey] [nvarchar] (450). The SQL server limits for the maximum size of index keys is specified at 900 bytes <a href="https://technet.microsoft.com/en-us/library/ms191241(v=sql.105).aspx" rel="noreferrer">here</a>. A note on that page specifically says </p>
  
  <blockquote>
    <p>"If a table column is a Unicode data type such as nchar or nvarchar,
    the column length displayed is the storage length of the column. This
    is two times the number of characters specified in the CREATE TABLE
    statement. In the previous example, City is defined as an nvarchar(30)
    data type; therefore, the storage length of the column is 60."</p>
  </blockquote>
  
  <p>So is this key not twice the allowed size?</p>
  
  <p>Sql Server Management Studio seems to think so....</p>
  
  <blockquote>
    <p>Warning! The maximum key length for a clustered index is 900 bytes.
    The index 'PK_AspNetUserLogins' has maximum length of 1800 bytes. For
    some combination of large values, the insert/update operation will
    fail.</p>
  </blockquote>
  
  <pre><code>CREATE TABLE [dbo].[AspNetUserLogins](
      [LoginProvider] [nvarchar](450) NOT NULL,
      [ProviderKey] [nvarchar](450) NOT NULL,
      [ProviderDisplayName] [nvarchar](max) NULL,
      [UserId] [nvarchar](450) NOT NULL,
   CONSTRAINT [PK_AspNetUserLogins] PRIMARY KEY CLUSTERED 
  (
      [LoginProvider] ASC,
      [ProviderKey] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  </code></pre>