temp-tables

Why is this CTE so much slower than using temp tables?

和自甴很熟 提交于 2019-12-11 04:04:19
问题 We had an issue since a recent update on our database (I made this update, I am guilty here), one of the query used was much slower since then. I tried to modify the query to get faster result, and managed to achieve my goal with temp tables , which is not bad, but I fail to understand why this solution performs better than a CTE based one , which does the same queries. Maybe it has to do that some tables are in a different DB ? Here's the query that performs badly (22 minutes on our hardware

Cannot reach a temp table using Java SQL Statement object passed as a Map Value

元气小坏坏 提交于 2019-12-11 03:22:48
问题 My code currently works something similar to this public void foo (Statement st, String sqlStr, String tempTableName) { String aString = foo(tempTableName); boolean result = st.execute(aString); // creates temp table // Now do something else in another method writeToTT(st, tempTableName); } public void writeToTT(Statement st, String tempTableName) { // Final String name String finalSqlWithTempTableName = foo(tempTableName); st.execute(finalSqlWithTempTableName); } The above works fine.

Insert records if not exist SQL Server 2005

泄露秘密 提交于 2019-12-11 02:05:11
问题 SQL Server 2005 Database. I have a temporary table with many records, these records are coming from an RSS feed and need to be inserted periodically. Some of the data will change, and some will remain the same. I only need to insert the 'new' records, and eliminate the chance of inserting redundant data resulting in duplicate records. How do I accomplish this? Example, tempTable, BEGIN INSERT INTO myTable ( row1 ,row2 ,row3 ) SELECT row1 ,row2 ,row3 FROM @tempTable END 回答1: One way is a not

How to get results of stored procedure #1 into a temporary table in stored procedure #2

折月煮酒 提交于 2019-12-10 21:24:50
问题 I am trying to combine the results of several stored procedures into a single temporary table. The results of the various stored procedures have the same column structure. Essentially, I would like to UNION ALL the results of the various stored procedures. A significant fact: each of the stored procedures creates a temporary table to store its data and the results each returns are based on a select against the temporary table: create proc SP1 as . . <snip> . select * from #tmp -- a temporary

How to combine data into a temporary table in Mysql

岁酱吖の 提交于 2019-12-10 20:09:43
问题 I have a very large table called paypal_ipn_orders . In this table I have 2 important bits of information a row called item_name and a row called sort_num . I want to use certain parameters to pull out records from paypal_ipn_orders and put them into a temporary table called temp_table . I know how to select the records as follows SELECT `item_name`, `sort_num` FROM `paypal_ipn_orders` WHERE `packing_slip_printed` = 0 AND LOWER(`payment_status`) = `completed` AND `address_name` <> '' That

How can I populate temporary tables, filter them, and then loop through (SQL Server)?

青春壹個敷衍的年華 提交于 2019-12-10 19:46:30
问题 I have a one-time operation I need to perform, and am hoping I can do it with a SQL statement (in LINQPad). I need to grab data from two tables, then insert those vals into another one. Specifically, I need to populate the CustomerCategoryLog table with data for each unique combination of Unit/MemberNo/CustNo from the Customers table, adding the corresponding NewBiz value from the MasterUnitsProjSales table. Pseudo-SQL is something like this: // First, need each unique combination of Unit,

TADOQuery Temp Table Lost if it has a parameter in query

我是研究僧i 提交于 2019-12-10 17:18:00
问题 I have a TADOQuery that generates a tempTable if I hard code the "Where parameter, it works fine, but if I use a TADO Parameter the next query doesn't know about the temp table. What am I doing wrong? I wish I could simplify this example but here it is. (SQL Server) CREATE TABLE brFTNode_Children ( pID integer NOT NULL, cID integer NOT NULL, primary key (pID, cID) ); insert into brFTNode_Children values(1,2); insert into brFTNode_Children values(1,3); insert into brFTNode_Children values(3,4)

What's the scoping rule for temporary tables within exec within stored procedures?

风流意气都作罢 提交于 2019-12-10 15:47:09
问题 Compare the following stored procedures: CREATE PROCEDURE testProc1 AS SELECT * INTO #temp FROM information_schema.tables SELECT * FROM #temp GO CREATE PROCEDURE testProc2 AS EXEC('SELECT * INTO #temp FROM information_schema.tables') SELECT * FROM #temp GO Now, if I run testProc1 , it works, and #temp seems to only exist for the duration of that call. However, testProc2 doesn't seem to work at all, since I get an Invalid object name '#temp' error message instead. Why the distinction, and how

What are the use cases for temporary tables in SQL database systems?

删除回忆录丶 提交于 2019-12-10 15:30:12
问题 what are the main purposes for which temporary tables are used? I want to know the practical and commercial uses of temporary tables in actual softwares working in small and large scale companies. 回答1: In my experience, temporary tables are often used to store intermediate calculations in a complex series of CREATE or UPDATE queries that produce some sort of analysis result. An example might be the creation of summary tables for an OLAP database. Temporary tables are also sometimes used to

Using dapper, why is a temp table created in one use of a connection not available in a second use of the same connection

怎甘沉沦 提交于 2019-12-10 12:45:56
问题 I'm trying to perform a series of SQL*Server steps using dapper from C#. One step creates a temp table and populates it. Following steps query data from the temp table. The create/populate seems to run successfully, but the first query from the temp table fails saying: "Invalid object name '#GetPageOfGlobalUsers'." using (SqlConnection connection = DBConnectionProvider.CreateConnection()) { ... misc setup stuff... connection.Execute(@" create table #GetPageOfGlobalUsers(row int, EmailAddress