如何将现有表的结构复制到Table变量中? [英] How to copy structure of an existing table into a Table variable?
问题描述
大家好,
美好的一天,
我想要一个表变量,其中想要一个物理表的结构.
如何声明具有现有结构的表变量?
例如:
声明@tblTemp table()<-在这里,我坚持如何给出现有物理表的结构?
SELECT * INTO @tblTemp from tbl_PhysicalTable其中1 = 2 <-这不适用于表变量,但适用于临时表.
最后,我想在Table变量中插入一个带有条件和UNIONS的变量.
Hello All,
Nice Day,
I want to have a Table Variable, in which I want to have structure of a physical table.
How to declare a table variable with existing structure?
Eg:
Declare @tblTemp table() <-- Here I stuck with how to give structure of an existing physical table?
SELECT * INTO @tblTemp FROM tbl_PhysicalTable where 1=2 <-- This wont work for table variable, but works for Temporary Table.
And finally I want to do a insert into the Table variable like, with conditions and UNIONS.
INSERT @tblTemp (*)
(SELECT * FROM tbl_PhysicalTable WHERE nID= 1125
union
SELECT * FROM tbl_PhysicalTable1 WHERE nID= 1125)
然后,最后,我将获得@tblTemp的过滤结果.
如何实现呢?
在此先感谢.
谢谢与问候
PMM:)
Then Finally, I will have @tblTemp of filtered results.
How to achieve this?
Thanks in Advance.
Thanks and Regards
PMM :)
推荐答案
CREATE TYPE mytableType AS TABLE( MyField1 VARCHAR(50), MyField2 INT )
DECLARE @MyVarTable AS mytableType
INSERT INTO @MyVarTable ....
看看此处 [
Take a look at Here[^]
这篇关于如何将现有表的结构复制到Table变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!