Highlight a SELECT stmt and create a temp table definition from it.
Highlight a SELECT stmt and create a temp table definition from it. You often need to create #tables and you have a select to fill it with. However, you have to either create the #table manually or do a SELECT INTO into a real table and then script it out. It would be nice to be able to just take my SELECT and be able to get the #table definition for it.
-
Anonymous commented
SQL Prompt has a way to do this. You can select into a temp table
SELECT A, B, C INTO #TempTable FROM Table
Sometimes you have to run the query once first but you can hover over the #TempTable name and it will provide the CREATE Table script for that temp table. Just copy, paste at the top, generate the INSERT and remove the INTO #TempTable from the query.
Hope this helps, I use it a LOT.
-
Lee Robinson commented
I think this is the sixth or seventh time I have seen this mentioned. We should gather these together and sum up the votes.
-
Stephen commented
If the generated definition could include NOT NULL as appropriate, as against the SELECT INTO making every column NULL, that would help a lot.
-
Sean commented
Yeah, you can select into a #table, but that doesn't give you the definition, now does it?
-
Alex den Haan commented
You can also select into a temp table.
SELECT
fld1
,fld2
INTO #tmpTbl
FROM Tbl