Composite primary key

前端 未结 8 1542
旧巷少年郎
旧巷少年郎 2020-12-15 18:37

I am working on the design of a database that will be used to store data that originates from a number of different sources. The instances I am storing are assigned unique I

8条回答
  •  清酒与你
    2020-12-15 19:05

    Some people recommend you use a Globally Unique ID (GUID): merge replication and transactional replication with updating subscriptions use uniqueidentifier columns to guarantee that rows are uniquely identified across multiple copies of the table. If the value if globally unique when it's created, then you don't need to add the source_id to make it unique.


    Although a uniqueid is a good primary key, I agree that it's usually better to use a different, natural (not necessarily unique) key as your clustered index. For example if a uniqueid is the PK which identifies employees, you might want to clustered index to be the department (if your select statements usually retrieve all employees within a given department). If you do want to use a unqiqueid as the clustered index, see the NEWSEQUENTIALID() function: this creates sequential uniqueid values, which (being sequential) have better clustering performance.

提交回复
热议问题