SQL system data type synonym name lost and replaced during parsing
ScriptDom version: 161.9142.1 Compatibility level: 150
While trying to implement custom TSQL linter rule which should prevent developers from using non-conventional data type names (synonyms) I've faced an issue: ScriptDom modifies type name during parsing. Which makes detection of synonym usage impossible or hard to implement.
For example:
DECLARE
@a NATIONAL CHARACTER VARYING (100)
, @b DOUBLE PRECISION
, @c INTEGER
Here only "INTEGER" synonym (for INT data type) can be easily detected. Data type name for @a is delivered to DatatypeReference.Name.BaseName partially: it contains CHARACTER word only. Yes, "character" is a synonym as well, but not the one that was actually provided.
Moreover, DOUBLE PRECISION gets lost totally: DatatypeReference.Name.BaseName.Value here comes as Float. It's good to know that the parser knows what is what but actual script contents disappeared after parsing - IMHO this is no good.
I'd expect ScriptDom parser to keep what was provided - a full original data type name no matter if it was a UDT or registered sql-server supplied type synonym. As far as I can understand ScriptDom has SqlDataTypeOption for internal needs and this DatatypeReference's property does contain NVarChar and Float as expected for both of mentioned examples above. Seems like BaseName could keep the original type name.
NATIONAL TEXT => BaseName.Value = TEXT, SqlDataTypeOption = NText