Uniqueidentifier vs conventional id (SQL Server)

0

Good morning, today I want to ask a question about performance (time) on what is more efficient, if you have a conventional id, type INT , or have a column type UniqueIdentifier .

With respect to the statement they are practically the same, the difference is that the UniqueIdentifier does not apply IDENTITY , if not a DEFAULT NEWID()

CREATE TABLE miTablaConvencional
(
    id INT NOT NULL PRIMARY KEY IDENTITY(1,1),
    campo VARCHAR(1)
)

CREATE TABLE miTablaUnique
(
    id UNIQUEIDENTIFIER NOT NULL PRIMARY KEY DEFAULT NEWID(),
    campo VARCHAR(1)
)

Which of the two tables would be more efficient, if you had to make queries by comparing your primary key fields and why.

Note:

Here and here , I leave information about UNIQUEIDENTIFIER

    
asked by Randall Sandoval 15.12.2016 в 16:47
source

1 answer

1

I'll put it another way.

To make comparisons, the two forms are exactly the same.

However, as you specified in the links, using a uniqueId is a problem when making inserts. You have to get rid of the clustered index and apply it to another field if necessary. In addition, IDs are not very readable.

Azure uses them because you are in the cloud, and your base could be distributed, you need them to be able to merge or partition the table. However, it would be unwise for a corporate or home base. The overhead that is added is not worth it.

    
answered by 15.12.2016 / 18:44
source