Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum length for a fully qualified quoted object name

I would like to get confirmation on the maximum length of a fully qualified SQL Server object name.

Please vote on the answer below if you agree. (I won't get points for these votes)

Currently I worked out the following:

  • The datatype should be nvarchar
  • The fully qualified object name is <Server>.<Database>.<Schema>.<Object>
  • Each part can have 128 characters (sysname = nvarchar(128))
  • quotename() of a 128 character string is maximum (128*2)+2 (each character escaped + open and close square brackets)
  • each name part gets separated by a .

This makes (((128*2)+2)*4)+3 = 1035

From that I derive the formula: (((128*2)+2)*@nr_of_name_parts)+(@nr_of_name_parts-1)

I think the formula is correct because plugging in 3 parts ends up with 776 which happens to be the param length of the sp_recompile procedure

like image 995
Filip De Vos Avatar asked Jan 01 '26 00:01

Filip De Vos


1 Answers

(Answering my on question as community wiki, based on the comment of Mikael Eriksson)

  • The datatype should be nvarchar
  • The fully qualified object name is <Server>.<Database>.<Schema>.<Object>
  • Each part can have 128 characters (sysname = nvarchar(128))
  • quotename() of a 128 character string is maximum (128*2)+2 (each character escaped + open and close square brackets)
  • each name part gets separated by a .

This makes (((128*2)+2)*4)+3 = 1035

From that I derive the formula: (((128*2)+2)*@nr_of_name_parts)+(@nr_of_name_parts-1)

I think the formula is correct because plugging in 3 parts ends up with 776 which happens to be the param length of the sp_recompile procedure

like image 97
3 revsFilip De Vos Avatar answered Jan 03 '26 12:01

3 revsFilip De Vos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!