Questions tagged [temp-tables]

Temporary tables are a feature of RDBMS's as a means of storing intermediate results. Some RDBMS's make the distinction between local and global temporary tables. Temporary tables are typically dropped when the session ends for local, or when the temporary table is no longer referenced for global. Note that a temporary table is not the same as a table variable even though both are temporary in nature.

The term temporary table is somewhat misleading, because the tables are permanent, just the data is somewhat volatile.

Temporary tables are useful to store intermediate data. Since it only exists for a session or a transaction the RDBMS doesn't have to worry about locks in order to synchronize between different transactions or redo information. This makes temporary tables often faster and more efficient then normal tables.

1637 questions
0
votes
1 answer

SQL Server DISTINCT OR GROUP BY WITH TEMP TABLES

I have a kind of complicated issue. The idea is, I need the distinct Serv_Acct from a table (This is easy and I already have that): DECLARE @CustomerID int = 8, @UtilityCompanyID int = 1 SELECT DISTINCT SERV_ACCT, MAX(INV_DATE) FROM…
Natalia Natalie
  • 647
  • 3
  • 10
  • 17
0
votes
1 answer

Stored procedure using temp tables not performing well

I am working with an ERP system that is MS SQL Server based. It has a shipment commit process that uses 99 temp tables to perform its work. The work needs to be atomic - it all needs to happen or non of it should happen. This particular stored…
0
votes
2 answers

Check if declared global temporary table exists in current session

How can I check if a declared global temporary table in DB2 exists or not in the current session? I need to create the temporary table once for a user session and then be able to insert rows in it each time a report is executed in the case of my…
Bernice
  • 2,552
  • 11
  • 42
  • 74
0
votes
2 answers

How to create a temporary table in MySQL to output table data as a CSV file?

I've got a script for creating a CSV file from a database table, which works fine except that it outputs all the data in the table, and I need it to output data only for the current logged in user. The app I'm developing is for users to be able to…
BlissC
  • 841
  • 3
  • 14
  • 18
0
votes
1 answer

Insert variables into temp table using union all

Why am I getting an incorrect syntax near 'dbo'. error? SELECT inv_num INTO #InvoiceList FROM ( SELECT inv_num = dbo.ExpandKy(10, @Inv1) UNION ALL dbo.ExpandKy(10, @Inv2) UNION ALL dbo.ExpandKy(10, @Inv3) UNION ALL …
0
votes
2 answers

SQL: How to create a temp table and fill it with date within a select-from statement

I wish to create a temp table with 1 datetime column and then fill it with date(30 days before today). I wish to do all these in a select-from statement. I could do it with a "WITH" loop as below prior to the select-from statement. However, I wish…
Chappy
  • 9
  • 1
  • 1
  • 5
0
votes
1 answer

Creating a temporary table with one extra column using Hibernate

I have a sequence of 5 forms that an user has to fill up in my system. On each submitted form, I send the data to my java server and store this data on mySQL database using Hibernate. In this scenario, I may have some problems for example if an…
Felipe Mosso
  • 3,907
  • 11
  • 38
  • 61
0
votes
1 answer

Use #temp inside a parenthesis

How use a #temp inside a parenthesis? Or how to use a table variable inside a parenthesis? Clearly the real query is much more complex. Fails: IF OBJECT_ID(N'tempdb..#Temp', N'U') IS NOT NULL DROP TABLE #Temp CREATE TABLE #Temp (sID int NOT…
paparazzo
  • 44,497
  • 23
  • 105
  • 176
0
votes
1 answer

How to create and view the results of a temp table from a hierarchical (recursive) query in SQL Server 2008 R2

Good Day. I am trying to generate a temporary table after I get results from a hierarchical query, and then view those results, all within the same query (so the recurvise query gets the results I want from a table, then the CREATE TABLE query…
WCS
  • 93
  • 1
  • 3
  • 17
0
votes
1 answer

Populate Temp Table Postgres

I have the following three tables in the postgres db of my django app: publication { id title } tag { id title } publication_tags{ id publication_id tag_id } Where tag and publication have a many to many relationship. …
jac300
  • 5,182
  • 14
  • 54
  • 89
0
votes
1 answer

updating a temp table with data from two tables

I have created a temp table (@temptable) where i left a column blank because I will fill it with another select statement. I have a table that has 5 rows called books: BookNum | BookDesc | BookDate | ...... ---------|----------|----------|-------- …
rjbogz
  • 860
  • 1
  • 15
  • 36
0
votes
1 answer

ORACLE Temp table not session specific (ODP.NET)

I have a program that calls a stored procedure which uses a temp table. I notice the first time i make the call i get the right amount of data back, but every n calls the rows keep getting bigger. I looked into the issue and came to understand that…
Ramie
  • 1,171
  • 2
  • 16
  • 35
0
votes
1 answer

For XML Union with a temp table

I know how to do union's and spit out an XML file from different tables, however, I need to create a temp table that will house 3 records that I need to be a part of the XML File. The structure is exactly the same as the other tables. How would I…
user1366606
  • 111
  • 1
  • 2
  • 10
0
votes
1 answer

how to sum column i in temp table

SELECT @cinema_count = COUNT(c.[key]) FROM cinemas c SET @count = 0 WHILE @count < @cinema_count BEGIN SET @count = @count+1 SET @buffer = 'ALTER TABLE #temptable ADD cinema'+LTRIM(RTRIM(CAST(@count AS VARCHAR)))+' MONEY DEFAULT 0 WITH…
Dakoy
  • 53
  • 2
  • 12
0
votes
2 answers

Temporary Tables in Postgres Sql

I am facing a problem regarding global temporary tables in Postgres Sql. If two procedures: A() having a temporary table say temp(id, name) B() having a temporary table say temp(id, name, address) then if the procedure A is called first and…
user2346047
  • 213
  • 1
  • 2
  • 16
1 2 3
99
100