Creating a Primary Key on a temp table - When?

后端 未结 9 679
一个人的身影
一个人的身影 2020-12-29 04:16

I have a stored procedure that is working with a large amount of data. I have that data being inserted in to a temp table. The overall flow of events is something like

9条回答
  •  佛祖请我去吃肉
    2020-12-29 05:05

    I was wondering if I could improve a very very "expensive" stored procedure entailing a bunch of checks at each insert across tables and came across this answer. In the Sproc, several temp tables are opened and reference each other. I added the Primary Key to the CREATE TABLE statement (even though my selects use WHERE NOT EXISTS statements to insert data and ensure uniqueness) and my execution time was cut down SEVERELY. I highly recommend using the primary keys. Always at least try it out even when you think you don't need it.

提交回复
热议问题