temp-tables

SQL server temporary tables vs cursors

爷,独闯天下 提交于 2019-12-03 04:45:44
In SQL Server stored procedures when to use temporary tables and when to use cursors. which is the best option performance wise? If ever possible avoid cursors like the plague. SQL Server is set-based - anything you need to do in an RBAR (row-by-agonizing-row) fashion will be slow, sluggish and goes against the basic principles of how SQL works. Your question is very vague - based on that information, we cannot really tell what you're trying to do. But the main recommendation remains: whenever possible (and it's possible in the vast majority of cases), use set-based operations - SELECT, UPDATE

Are temporary tables thread-safe?

本秂侑毒 提交于 2019-12-03 00:56:36
I'm using SQL Server 2000, and many of the stored procedures it use temp tables extensively. The database has a lot of traffic, and I'm concerned about the thread-safety of creating and dropping temp tables. Lets say I have a stored procedure which creates a few temp tables, it may even join temp tables to other temp tables, etc. And lets also say that two users execute the stored procedure at the same time. Is it possible for one user to run the sp and which creates a temp table called #temp, and the another user runs the same sp but gets stopped because a table called #temp already exists in

Getting two issues while using stored procedure in MySQL

こ雲淡風輕ζ 提交于 2019-12-02 18:39:17
问题 Below is the sample code of my Stored Procedure in which I am working on for interest calculation. This code is not executable because according to finding its getting issue while defining creating temporary table block before the cursor declaration but if I define same thing recently after cursor declaration then it's executing successfully. 1- My question is I am using that table inside cursor so I must have to define after cursor or I have missed anything ?? CREATE PROCEDURE `sp_interest

why does updating a real table from a self-join temp table is not working but when using a real table it works?

点点圈 提交于 2019-12-02 18:08:18
问题 Here's the scenario: Procedure 1 creates temp table #t. Procedure 1 executes procedure 2. Procedure 2 populates #t. In procedure 1, I insert into a real table from #t just so I can view the data. The data is there. Immediately after viewing this data, I do an update with a self-join. Like so: update b set b.column1 = a.column3 from #t a inner join #t b on a.id = b.id; The record that is supposed to be updated IS NOT UPDATING. However, if I change #t to a real table "dbo.t" and do exactly the

Move one row value to another in SQL

霸气de小男生 提交于 2019-12-02 10:02:43
I currently have a temporary table like so DBName API50 CounterValue NULL NULL 1 test1 34.5 NULL NULL NULL 2 test1 38.5 NULL I want a script which will make my temporary table as below DBName API50 CounterValue test1 34.5 1 test1 38.5 2 If your table has a primary key, and you always want to associate the CounterValue field with the next field in the table, you can do a self-join: SELECT t1.DBName, t1.API50, t2.CounterValue FROM MyTable t1 INNER JOIN MyTable t2 ON t1.PrimaryKey -1 = t2.PrimaryKey WHERE t1.DBName IS NOT NULL I like AHiggins answer as it solves the problem in SQL as it is

Alternate method to global temp tables for Oracle Stored Procedure

自古美人都是妖i 提交于 2019-12-02 08:18:22
I have read and understand that Oracle uses only global temp tables unlike MS SQL which allows #temp tables. The situation that I have would call for me to create hundreds of Global temp tables in order to complete the DB conversion I am working on from MS SQL to Oracle. I want to know if there is another method out there, within a Oracle Stored Procedure, other than creating all of these tables which will have to be maintained in the DB. Thank You " Most of the time the only thing the temp tables are used within a stored proc and then truncated at the end. We do constant upgrades to our

why does updating a real table from a self-join temp table is not working but when using a real table it works?

烈酒焚心 提交于 2019-12-02 08:07:39
Here's the scenario: Procedure 1 creates temp table #t. Procedure 1 executes procedure 2. Procedure 2 populates #t. In procedure 1, I insert into a real table from #t just so I can view the data. The data is there. Immediately after viewing this data, I do an update with a self-join. Like so: update b set b.column1 = a.column3 from #t a inner join #t b on a.id = b.id; The record that is supposed to be updated IS NOT UPDATING. However, if I change #t to a real table "dbo.t" and do exactly the same thing, it works. I'm so confused. Anyone has any idea why this could be? Thanks. Per the MS SQL

Getting two issues while using stored procedure in MySQL

≯℡__Kan透↙ 提交于 2019-12-02 08:07:24
Below is the sample code of my Stored Procedure in which I am working on for interest calculation. This code is not executable because according to finding its getting issue while defining creating temporary table block before the cursor declaration but if I define same thing recently after cursor declaration then it's executing successfully. 1- My question is I am using that table inside cursor so I must have to define after cursor or I have missed anything ?? CREATE PROCEDURE `sp_interest_calculation_test`( IN sub_type CHAR(1) ) BEGIN DECLARE s_ledger_id INT; DECLARE s_start, s_end, s_tran

Dynamic query results into a temp table or table variable

萝らか妹 提交于 2019-12-02 02:27:58
I have a stored procedure that uses sp_executesql to generate a result set, the number of columns in the result can vary but will be in the form of Col1 Col2 Col3 etc. I need to get the result into a temp table or table variable so I can work with it. The problem is I need to define the columns of the temp table, which I cant do dynamically using sp_executesql as the scope of the temp table is lost after the command is executed. I have toyed with the idea of using Global Temp tables, as the scope allows it to be created dynamically, however, there is a very good chance the Global Temps would

Dynamic query results into a temp table or table variable

我的梦境 提交于 2019-12-02 01:45:22
问题 I have a stored procedure that uses sp_executesql to generate a result set, the number of columns in the result can vary but will be in the form of Col1 Col2 Col3 etc. I need to get the result into a temp table or table variable so I can work with it. The problem is I need to define the columns of the temp table, which I cant do dynamically using sp_executesql as the scope of the temp table is lost after the command is executed. I have toyed with the idea of using Global Temp tables, as the