create temporary table in sql

Results 1 to 2 of 2

Thread: create temporary table in sql

  1. #1
    Join Date
    Dec 1969

    Default create temporary table in sql

    Hi, <BR><BR>How do you create a sql temporary table to hold the results from a select statement which will then be used to further access data from other tables that share this common data that resides in the temporary table. Thanks.<BR>P.S. I have seen this question posted at least twice previously with no response. I would truly appreciate any help. Thanks!!!

  2. #2
    Mark F Guest

    Default RE: create temporary table in sql

    I&#039m not sure if this is what you&#039re asking but...<BR><BR>Creating temporary tables is easy in SqlServer and Sybase (Oracle does not have such a thing!) and they can come in really handy. There are two types: local and global. Local is only available to you and is automatically dropped at the end of the current session or proc. The easiest way to create them is to name them with a # (local) or ## (global). They are created automatically in the tempdb database. You can easily create them with a SELECT INTO clause (ex. SELECT * INTO #temp1 FROM Pubs). As long as you are still in the same session, you can then use a join to the temp table (#temp1 in the example above) just like any other table. SqlServer knows that the # tablenames are in tempdb database automatically. You don&#039t even have to drop the table, it will be done for you. The only caution is that tempdb is a shared pool of space, so make sure you have enough space for what you and all others are doing.<BR><BR>Anyway, hope that helps???<BR><BR>Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts