views:

32

answers:

3

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 2005?

+3  A: 

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.

OMG Ponies
It would have been too good to be true if these alternatives existed. Thanks for the knowledge!
PJ
+1  A: 

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).

AdaTheDev
A: 

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.

Philip Kelley