Tuesday, March 27, 2012

Create a table variable from an existing table's schema

Hello.
What's the best way to copy a table's schema and create a "table" data type
inside of a stored procedure?
Thanks in advance,
MikeI think your only choice will be dynamic sql, and you will not have the
chance to access this variable from the original procedure. What are you
trying to do?. Can you use a temporary table created with SELECT ... INTO ..
.
FROM?
select col1, ..., coln
into #t
from table1
where 0 = 1
...
AMB
"MikeL" wrote:

> Hello.
> What's the best way to copy a table's schema and create a "table" data typ
e
> inside of a stored procedure?
> Thanks in advance,
> Mike
>
>|||> What's the best way to copy a table's schema and create a "table" data
type
> inside of a stored procedure?
Well, if you have to rely on dynamic determination of the data model, then
in my opinion: use a temp table. You can't use SELECT INTO for @.table
variables. Some other differences are listed here:
http://www.aspfaq.com/2475
There is no substitute for understanding your data model and not having to
generate this kind of thing on the fly. Why do you need to copy the
structure at all?
Please post DDL, sample data and desired results.
See http://www.aspfaq.com/5006 for info.

No comments:

Post a Comment