Is there a way to bind a variable type to column data type?
In Oracle PL/SQL, you can always bind your code variables' type to a specific table.column type like this:
myVar TABLE.COLUMN%TYPE
So, if you change the column's type, you don't have to go over your code to re-define related var types (of course you'd still need to check you are properly using the variable).
Is there a similar way to define this in SQL Server 2开发者_JAVA百科005?
If there is one, I'd like to know but in my experience so far:
- %TYPE
- %ROWTYPE
...are not supported and do not have alternatives in TSQL.
No, you can't do that in SQL Server.
Closest I can think of is to use a user-defined type to "mask" the underlying type. But IMHO that's not ideal for what you want. Or there's sql_variant which is:
A data type that stores values of various SQL Server-supported data types.
But, again this would really be a cludge (with limitations).
If you are desparate, you could use the "sql_variant" data type. However, it can be awkward to use, and has always seemed to be a kludge to me.
精彩评论