开发者

Declaring variable type based on a column type

In Oracle's PL-SQL, you can declare a variable and define its type based on a table column:

declare var1 table.column%TYPE;

Is it possible to do som开发者_如何学编程ething similar in MS SQL Server?


No you can't do this. The closest equivalent is User-Defined Data Types. This will give you a layer of abstraction that may help, but it is not the same as deriving a type from a column.


It may skirt the real issue, but you can "cheat" a little bit by

Select *
INTO #tmp
From MyTable
Where 1 = 0

Will automatically create a temp table with all columns with correct data types.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜