Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the benefits of storing name as "sysname" instead of "nvarchar(128)"?

I looking to create a table that will store information about stored procedures. I need to store SP_Name. My original plan was to use SP_Name NVARCHAR(128) NOT NULL.

From procedure I will use OBJECT_NAME(@@PROCID) function to get value for SP_Name column.

This technet does not provide much information about the SYSNAME datatype. What is SYSNAME data type in SQL Server? question only explains what it is but not how it works, additionally answer is almost 3 years old and Microsoft made many upgrades to SQL Server in 2012 and 2014 editions.

Will I again any benefits of storing SP_Name in SYSNAME over NVARCHAR(128) column? Or should I avoid use of proprietary data types that might be dropped or changed in later version?


1 Answers

It provides an abstraction that shields you from the implementation details. The benefit is that if the definition changes in future versions your code will still work correctly.

sysname used to be equivalent to varchar(30). If, say, SQL Server 2016 allows object identifiers to be 256 characters long you don't need to find and update all the hardcoded 128.

I also prefer using it as it seems neater semantically anyway to use that datatype for columns/variables storing object identifiers.

like image 105
Martin Smith Avatar answered Oct 26 '25 08:10

Martin Smith