Which is the better method to add the Row Number?

Отвечено Which is the better method to add the Row Number?

  • 3 мая 2012 г. 3:20
     
     

    Hi All,

    I had a requirement in which I need to have a unique row number to the temp table or table variable. One of the method I got was from here. Other is to have a identity column. Performance wise which one is better? Any Suggestion?

    techknackblogs

Все ответы

  • 3 мая 2012 г. 3:38
     
     Предложенный ответ
    Identity column value is increased automatically by the Increment value during each insert operation and it would be always unique. In most cases Identity column would be used as the Primary key as well which would be created as a clustered index. I would go for Identity field rather than increasing the number manually..

    Murali Krishnan

  • 3 мая 2012 г. 3:43
     
     Отвечено

    If you will use IDENTITY column, the overhead on top of pure inserts is minimal (assuming that IDENTITY column is created with the table).

    If you will use UPDATE or ALTER TABLE, it will process whole existing table and it is saved second time to disk.

    • Помечено в качестве ответа Rishi Daftary 3 мая 2012 г. 3:48
    •  
  • 3 мая 2012 г. 3:45
     
     

    So you mean to say Performance wise Identity Column is better than the other way round...

    techknackblogs

    • Предложено в качестве ответа Anshu M 3 мая 2012 г. 6:43
    • Отменено предложение в качестве ответа Anshu M 3 мая 2012 г. 8:06
    •