Search code examples
sql-serverviewtemporary

Creating temporary view from a temporary table in SQL Server


I have a temporary table and I would like to create a temporary view over this temporary table.

Is it possible?

In following example I would like #Top10Records to be a view instead of a table so that I get

select * into #Top10Records from (select top 10 * from #MytempTable)

Solution

  • Unfortunately, SQL Server doesn't support this:

    Msg 4103, Level 15, State 1, Line 3
    "#someView": Temporary views are not allowed.
    Msg 4508, Level 16, State 1, Line 6
    Views or functions are not allowed on temporary tables. Table names that begin with '#' denote temporary tables.