I was walking view definitions in a database today using sqlalchemy 0.6 (using get_view_definition()) and I ran across one that was larger than 4000 characters. MS seems to say (Information Schema Views for VIEWs) that shouldn’t be returned. MS SQL Server Management Studio shows the whole thing (well at least the beginning and the end look right) if you ask for the design of the view. sqlalchemy returns a string truncated at 4000 characters (boo, hiss). How can I ask the database what type it wants to return for this piece of data instead of depending on what I suspect is out of date documentation. I’m assuming the type is probably varchar. I would just like to verify that.
I was walking view definitions in a database today using sqlalchemy 0.6 (using get_view_definition())
Share
The object definitions, including view definitions, can be retrieved from the
sys.sql_modulesview, or using theOBJECT_DEFINITIONfunction. This includes the properNVARCHAR(MAX)type that contains the untruncated definition of the object.Other backward compatibility views like
sys.syscommentsorINFORMATION_SCHEMA.VIEWScontain a column of typeNVARCHAR(4000)and such a type, by definition, must truncate the object definition after first 4k characters. Many cross platform tools will rely on theINFORMATION_SCHEMAviews and perhaps sqlalchemy does the same.