Jacob Alley Jacob Alley - 1 year ago 83
SQL Question

Sql Server Data Types

I am writing a script that will generate a column of every data type within sql server. I know that sql-server considers things like decimal(5,1) and decimal(5,0) as different data types, however the various resources that I have looked at (w3schools and the microsoft reference page) do not make it clear if this is also the case for things like: Binary (length), or datetimeoffset(0-7), etc. Any insight would be greatly appreciated.

Answer Source

I'd say the answer is a bit messy.

On the one hand the SQL Server datatypes page clearly makes a distinction between "data types, collations, precision, scale, or length".

So that would indicate that collations, precision, scale, or length are all attributes distinct from datatype.

However the same page also mentions

Large value data types: varchar(max), nvarchar(max), and varbinary(max)

So that would imply that adding the max does change the datatype in some sense. Then also you've got cases like float(24) which is treated in SQL Server as a distinct datatype of real.

What is the purpose of this script? Simply generating a column of every data type doesn't sound useful in its own. What is it for? What makes sense for the script?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download