Is there an order of precedence in executing SQL commands?

Posted on 2011-10-19
Last Modified: 2012-05-12
I have a very large database, with about 1 million users and also a large number of queries running simultaneously. Sometimes the database freezes. It only reads records (SELECT), but does not make any INSERTS nor UPDATES.

I guess the INSERTS get stuck in the spool.

Is there an order of precedence in executing these SQL commands? Does SQL server first do all SELECTS and them execute INSERTS and UPDATES?

Is there a solution for this? Basicly the INSERTs and UPDATEs are used for my Ad Server (check if the media exists, insert or update click and pageview records).
Question by:hmiura
    LVL 37

    Expert Comment

    "with about 1 million users" ?? USERS?
    LVL 142

    Accepted Solution

    sql statements are bascially first in first out.

    apart from that, if your database "freezes", it can be:
    * the database is currently "growing" (extending a data or log file)
     => should be avoided by sizing the files correctly, resp adding/resizing them at low-traffic hours.

    * the database has a couple of statements that are starting to lock each other
      => missing indexes?


    Author Comment

    "1 million users" ... I mean registered users. Not everybody at the same time. But we have a very high number of pageviews and user interaction within the portal.

    Author Closing Comment

    Thanks for your help. I'll try creating more indexes and see if it really keeps DB cool.
    LVL 29

    Expert Comment

    by:Rich Weissler
    Just a side note -- Indexes help with READ (Select) performance, at the expense of WRITE (Update/Insert) performance.  If you add additional indexes, do not be surprised if insert/update performance gets worse.

    What you might want to check is to see whether the index/updates are being blocked... (you should be able to see that in the activity monitor or the sp_who stored procedure.)

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Join & Write a Comment

    Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now