SQL Server Performance

How to otptimize this query

Discussion in 'Performance Tuning for DBAs' started by Lance4848, Dec 24, 2004.

  1. Lance4848 New Member

    INSERT INTO monitordata
    SELECT * FROM data (NOLOCK) WHERE DATEDIFF(hh,time_stamp,@now) > 6

    DELETE data WHERE DATEDIFF(hh,time_stamp, @now) > 6

    Thanks in advance
  2. derrickleggett New Member

    Get rid of the * and replace it with the column names. Place the date logic so you're not causing a table scan and can use the indexes.

    SELECT col1, col2 FROM data WITH(NOLOCK) WHERE time_stamp > DATEADD(HH,@now,6)

    This should give you an idea.


    When life gives you a lemon, fire the DBA.

Share This Page