Mike Yearwood
Toronto, Ontario, Canada
General information
Forum:
Microsoft SQL Server
>Hi,
>
>I was creating a report based on a table in SQL Server and noticed that it was very slow. I realized that the problem was that the field/column used in selecting the records didn't have an index. I added an index on this field/column and report performs much better.
>
>But I also noticed that this table has an identity field but it is not set as Primary Key. How important is it to set an identity column as a Primary Key (which of course will create the index)?
I use the NewSequentialGUID as the primary key - unclustered. I usually have a meaningful key which the users can see. That key may or may not be clustered. The users can change that if needed, but never the guid. The NewSequentialGUID is generated as a default value when a record is added. It's demonstrably fast for inserts. There are no cascade updates. The guids are collected in fewer pages because they are sequential. Record retrieval is fast too. It's almost as fast as integers. It's needed if you're going to do replication. You have to have an index on a primary key and pay the hit for updating it. It lets your users search by their meaningful key - which is usually longer than an integer, and then you obtain the guid per their search and use that to get the matching record and for child records.
Previous
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only