Is there a SQL statement that can return the type of a column in a table?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
INFORMATION_SCHEMA.COLUMNSview, which SQL Server supports.DATA_TYPEcolumn contains the T-SQL/SQL Server type names, except that it doesn’t include arguments for parameterised types, which can result in unexpected/unintentional column behaviour.nvarchar(max),datetime2(3), anddecimal(10,5)then the output will benvarchar,datetime2, anddecimalrespectively.nvarchar(without(max)or(123)) is the same asnvarchar(1), and usingdecimalis the same asdecimal(18,0)which cannot store non-integer values.CHARACTER_OCTET_LENGTH(forbinary),CHARACTER_MAXIMUM_LENGTH(forcharandnchar),DATETIME_PRECISION(fordatetime2anddatetimeoffset), andNUMERIC_PRECISIONwithNUMERIC_SCALE(fordecimalandnumeric) in order to reconstruct the type’s parameter values.float(n)can be ignored as SQL Server only supportsfloat(24)andfloat(53)which are aliased byrealandfloatrespectively in theDATA_TYPEcolumn.Gives results like this: