TSQL Variable Definition based on Column Type

Published 12 March 6 1:29 AM | GregLow

I ran into Scott Thornton at the VDNUG meeting in Melbourne a week or so ago. Scott was a student I had taught in a SQL Server class last year. He sent me a number of suggestions regarding enhancements to T-SQL he'd like to see, particularly ones he misses from Oracle. One that really caught my eye was on variable declarations.

Currently, when you declare a variable in T-SQL, you need to provide the data type. Often you are picking a type which is compatible with an existing database column type. The problem is that if the column type in the database changes, you can need to update a large number of procs, etc.  that use that type. Instead, it would be great if you could define a variable as:

DECLARE @TradingName dbo.Customers.TradingName

I'd really love to see that. I've posted it to the MS feedback centre. If you'd like to see it, the place to vote for it is:

http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=10b76ad8-6db1-4048-89c4-618b1c74b8b5