Re: temp tables and locking issues

hkvats_1999_at_yahoo.com
Date: 06/25/04


Date: 25 Jun 2004 02:05:46 -0700

Hi Zidgan,

Your post made me think, how we can avoid the use temporary tables....
 and i tried to finds some articles for exact explainations....

Here is my finding after reading several articles on web and testing
these in SQL Server .....

When you create a temporary tables......... following steps taken by
SQL Server...

1) Lock tempdb database
2) CREATE the temporary table (write activity)
3) SELECT data & INSERT data (read & write activity)
4) SELECT data from temporary table and permanent table(s) (read
activity)
5) DROP TABLE (write activity)
4) Release the locks

Now it can be concluded....

> Is the tempdb only locked during the time the table is being created?
- DB Locked
>
> Is it locked during the entire time of the Select Into process?
> DB Lockaed
>
> Is the tempdb locked during any transactions using it?
> DB Locked

for details you can refer
http://www.sql-server-performance.com/jg_derived_tables.asp article...

Regards
Hari Sharma

Zidgan <rcloninger@triad.rr.com> wrote in message news:<4ej1d09ceucb3hulhp0jme5ld8p09r1nti@4ax.com>...
> I am a developer and am by no means an expert in SQL. I have used temp
> tables frequently, especially in nested stored procedures against our
> SQL Server 2000 database. However, recently I have found many
> articles on the web warning about performance issues with temp tables.
>
> One concern is locking. Each article seems to explain it differently.
> One article simply said not to use them because the tempdb is locked
> while the "select into" was running. Another article seemed to imply
> the tempdb is locked only while the database is trying to define the
> temporary table on a SELECT INTO command. Still another said it was
> locked during a transaction. Today I tried a number of tests trying
> to ascertain what was locked and when. So far I have not been able to
> validate any of these things.
>
> I would appreciate a clarification on this, and possibly some sample
> code, perhaps against the Northwinds database, that could show the
> effect of the locking. If it is a problem, I would like to
> demonstrate it to the other developers. The questions are:
>
> Is the tempdb only locked during the time the table is being created?
>
> Is it locked during the entire time of the Select Into process?
>
> Is the tempdb locked during any transactions using it?
>
> I appreciate advice from the experts. Thanks



Relevant Pages

  • Re: Want to write your SQL statements and even stored procedures in pure C#?
    ... I'll be writing more articles soon. ... > your reasoning is that you claim your solution is truly database ... SQL server, DB2, and Firebird. ... Second of all - sequences are not horrible, identity fields are the item that is poor. ...
    (microsoft.public.dotnet.framework.adonet)
  • SQL-DMO and VB.Net
    ... articles is created. ... for there to be a database on MSDE that you can use as one ... snapshot and merge agents. ... >The primary database is on the SQL Server. ...
    (microsoft.public.sqlserver.replication)
  • Re: Article Storage: Files vs. Database
    ... loading articles from a database does not appear to be as efficient as simply displaying files. ... Jonathan Wood ... Some advantages of storing them in the database are ease of some operations, and the option of using SQL Server 2005 text index to implement search. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Huge Replication Scenario
    ... As to the latencies, that’s exactly the bottleneck in performance, which ... SQL Server installations. ... articles needed for our system? ... What concerns us is our huge database, ...
    (microsoft.public.sqlserver.replication)
  • Re: Article Storage: Files vs. Database
    ... some third party solution like dtSearch or open source (just google "serarch ... SQL Server 2005's full-text indexing yet? ... With file-based articles, ... indexed by the database, or to store the article text in the database. ...
    (microsoft.public.dotnet.framework.aspnet)

Loading