SQL Server: Maximum character length of object names

Sql ServerSql Server-2008Tsql

Sql Server Problem Overview


What is the maximum character length of object name (e.g. constraint, column) in SQL Server 2008?

Sql Server Solutions


Solution 1 - Sql Server

128 characters. This is the max length of the sysname datatype (nvarchar(128)).

Solution 2 - Sql Server

Yes, it is 128, except for temp tables, whose names can only be up to 116 character long. It is perfectly explained here.

And the verification can be easily made with the following script contained in the blog post before:

DECLARE @i NVARCHAR(800)
SELECT @i = REPLICATE('A', 116)
SELECT @i = 'CREATE TABLE #'+@i+'(i int)'
PRINT @i
EXEC(@i)

Solution 3 - Sql Server

You can also use this script to figure out more info:

EXEC sp_server_info

The result will be something like that:

attribute_id | attribute_name        | attribute_value
-------------|-----------------------|-----------------------------------
           1 | DBMS_NAME             | Microsoft SQL Server
           2 | DBMS_VER              | Microsoft SQL Server 2012 - 11.0.6020.0
          10 | OWNER_TERM            | owner
          11 | TABLE_TERM            | table
          12 | MAX_OWNER_NAME_LENGTH | 128
          13 | TABLE_LENGTH          | 128
          14 | MAX_QUAL_LENGTH       | 128
          15 | COLUMN_LENGTH         | 128
          16 | IDENTIFIER_CASE       | MIXED
           ⋮  ⋮                       ⋮
           ⋮  ⋮                       ⋮
           ⋮  ⋮                       ⋮

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjraraView Question on Stackoverflow
Solution 1 - Sql ServerMartin SmithView Answer on Stackoverflow
Solution 2 - Sql ServerJaimeView Answer on Stackoverflow
Solution 3 - Sql ServerGorkemHaluluView Answer on Stackoverflow