sql server - Should you put Indexes on a SQL Table that you are updating? -


We have a working table that we make over one million records every night. It takes about 3 hours to complete this process overnight. In the process we first include all the data in the table. Then we make many updates to the table.

For example:

  Set as a working table from a.Field1 = b.Field1 as a Join table 2 where a.ID = B.ID   

At this point we do not have any indexes or keys specified on workingtable .

>

To answer this question, you must first know how keys and indexes work in SQL Server.

A primary key, by default, is a compiled unique index. Although this is slow to record, the recession should be reduced. The actual drop in the display is usually a where a SQL query or a DML statement occurs in the section, which causes the table scan if you update enough records after the initial creation, then Adding a primary key or clustered unique index to the ID column will be a performance win.

In fact, the primary key or an index falls below this question:

Who generates "id"? An application to load data or databases?

If the application loaded application generates an "id" value, then there must be enough to add a compiled index to that column.

  idx_worktable_id on w. Create a workbook;   

If the database is generating these values, then just type the "ID" column int of the primary code:

  Alternative Table [WorkTable] Identification Identity Identity (1,1);   

With a few exceptions,

Each table should have package indicator. In addition to improving query performance, a package indicator on demand can be rebuilt or reconstituted to control table fission. A compiled indicator can also be made on one view.

Related:

If you need to update the indexed column values, then index can drag on the display. Every update in those column values ​​causes SQL Server to rebuild that index.

Examine this with an increase in performance, proof is in pudding.

Conclusion

  1. Write your own SQL to avoid the table scan.
  2. No
  3. Avoid adding unnecessary
  4. This is the basic performance guidelines for any SQL query.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -