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.
![](https://secure.gravatar.com/avatar/17c5f6be781cce7b1560fd6ad6e2a81c?size=40&default=https%3A%2F%2Fassets.uvcdn.com%2Fpkg%2Fadmin%2Ficons%2Fuser_70-6bcf9e08938533adb9bac95c3e487cb2a6d4a32f890ca6fdc82e3072e0ea0368.png)
-
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