temp-tables

Is there a way to get a list of all current temporary tables in SQL Server?

独自空忆成欢 提交于 2019-11-28 06:40:46
I realize that temporary tables are session/connection bound and not visible or accessible out of the session/connection. I have a long running stored procedure that creates temporary tables at various stages. Is there a way I can see the list of current temporary tables? What privileges do I need to be able to do so? Alternatively, Is there a way I can see the particular SQL statement being executed inside a running stored procedure? The procedure is running as a scheduled job in SQL Server. I am using SQL Server 2000. Thanks for your guidance. Sandro Is this what you are after? select * from

What to use? View or temporary Table

若如初见. 提交于 2019-11-28 05:15:13
I have a problem to decide whether to use a view or a temp table. I have a stored procedure that i call from program. In that SP i store the result of a long query in a temp table, name the columns and make another queries on that table store the results in labels or a gridview or whatever and drop the Temp Table. I could also store the query-result in a view and make queries on that view. So what is better or in what case do i HAVE to use a VIEW/ Temp Table. According to my research a view has the benefit of: Security, Simplicity and Column Name Specification. My temporary table fulfills all

TSQL select into Temp table from dynamic sql

心已入冬 提交于 2019-11-27 22:49:01
This seems relatively simple, but apparently it's not. I need to create a temp table based on an existing table via the select into syntax: SELECT * INTO #TEMPTABLE FROM EXISTING_TABLE The problem is, the existing table name is accepted via a parameter... I can get the table's data via: execute ('SELECT * FROM ' + @tableName) but how do I marry the two so that I can put the results from the execute directly into the temp table. The columns for each table that this is going to be used for are not the same so building the temp table before getting the data is not practical. I'm open to any

Is MySQL Temporary table a shared resource?

岁酱吖の 提交于 2019-11-27 13:42:00
问题 I have a MySQL stored procedure that uses a temporary table. Assume that my table name is 'temp' and I use it to store some middle data. It will create at the beginning of procedure, and will drop at the end. CREATE PROCEDURE p() BEGIN CREATE TEMPORARY TABLE \`temp\`(...); INSERT INTO \`temp\` VALUES(...); DROP TEMPORARY TABLE \`temp\`; END; The problem is that this stored procedure may be used by different users concurrently, so I want to know if this can cause any problems (i.e. any

SQL Server SELECT INTO and Blocking With Temp Tables

﹥>﹥吖頭↗ 提交于 2019-11-27 11:37:35
问题 So, recently a DBA is trying to tell us that we cannot use the syntax of SELECT X, Y, Z INTO #MyTable FROM YourTable To create temporary tables in our environment, because that syntax causes a lock on TempDB for the duration of the stored procedure executing. Now, I've found a number of things that detail how temporary tables work, scope of execution, cleanup and the like. But for the life of me, I don't see anything about blocking because of their use. We are trying to find proof that we

T-SQL Dynamic SQL and Temp Tables

岁酱吖の 提交于 2019-11-27 08:54:10
It looks like #temptables created using dynamic SQL via the EXECUTE string method have a different scope and can't be referenced by "fixed" SQLs in the same stored procedure. However, I can reference a temp table created by a dynamic SQL statement in a subsequence dynamic SQL but it seems that a stored procedure does not return a query result to a calling client unless the SQL is fixed. A simple 2 table scenario: I have 2 tables. Let's call them Orders and Items. Order has a Primary key of OrderId and Items has a Primary Key of ItemId. Items.OrderId is the foreign key to identify the parent

How to retrieve field names from temporary table (SQL Server 2008)

筅森魡賤 提交于 2019-11-27 06:51:44
I'm using SQL Server 2008. Say I create a temporary table like this one: create table #MyTempTable (col1 int,col2 varchar(10)) How can I retrieve the list of fields dynamically? I would like to see something like this: Fields: col1 col2 I was thinking of querying sys.columns but it doesn't seem to store any info about temporary tables. Any ideas? select * from tempdb.sys.columns where object_id = object_id('tempdb..#mytemptable'); select * from tempdb.INFORMATION_SCHEMA.COLUMNS where table_name like '#MyTempTable%' The temporary tables are defined in "tempdb", and the table names are "mangled"

db2 equivalent of tsql temp table

女生的网名这么多〃 提交于 2019-11-27 06:20:30
问题 How would I do the following TSQL query in DB2? I'm having problems creating a temp table based on the results from a query. SELECT COLUMN_1, COLUMN_2, COLUMN_3 INTO #TEMP_A FROM TABLE_A WHERE COLUMN_1 = 1 AND COLUMN_2 = 2 The error message is: "Error: SQL0104N An unexpected token "#TEMP_A" was found following "". Expected tokens may include: ":". SQLSTATE=42601" 回答1: You have to declare a temp table in DB2 before you can use it. Either with the same query you are running: DECLARE GLOBAL

Force Oracle Drop Global Temp Table

☆樱花仙子☆ 提交于 2019-11-27 06:11:31
问题 In our project I create some global temp table that will be like these: CREATE GLOBAL TEMPORARY TABLE v2dtemp ( id NUMBER, GOOD_TYPE_GROUP VARCHAR2(250 BYTE), GOOD_CODE VARCHAR2(50 BYTE), GOOD_TITLE VARCHAR2(250 BYTE) ) ON COMMIT PRESERVE ROWS; but the problem comes when I want to drop this table. Oracle will not let me to drop the table, and it says: ORA-14452: attempt to create, alter or drop an index on temporary table already in use I have to use this table in some procedure but it may be

Table variable poor performance on insert in SQL Server Stored Procedure

拜拜、爱过 提交于 2019-11-27 06:00:58
问题 We are experiencing performance problems using a table variable in a Stored Procedure. Here is what actually happens : DECLARE @tblTemp TABLE(iId_company INT) INSERT INTO @tblTemp(iId_company) SELECT id FROM ..... The SELECT returns 138 results, but inserting in the TABLE variable takes 1min15 but when I use a temp table with the same SELECT, woops, takes 0sec : CREATE TABLE #temp (iId_company INT) INSERT INTO #temp(iId_company) SELECT id FROM ... What could cause the behavior ? 回答1: Use a