Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Composite PK/Surrogate and Sequence/Identity questions.

$
0
0
So, I have some questions about best practice in SQL Server. 1.) I have PK like this (company TINYINT, store TINYINT, action TINYINT, invoice INT, sn SMALLINT). I know JOINS will work faster with surrogate key but I have only couple of JOINS on that table. I use members of PK in WHERE clause mainly, alone and combined for reporting purpose. Is it always better to have surrogate key because they don't have any meaning and context of data laying in current PK. Basically my question would be when to use surrogate key and be confident that I make right choice.2.) In my PK from above I have two candidates for using Sequence object. Invoice start with 1 for every (company,store,action) combination. Sn start with 1 for every (company,store,action,invoice) combination. I would like to know can I implement Sequence object here knowing that Sequence don't support PARTITION BY in OVER clause. From what I red it cannot be done via Sequence but I have to ask.Here is data sample for this PKcompany store action invoice sn----------- ----------- ----------- ----------- -----------1 1 1 2017 11 1 1 2018 11 1 1 2019 11 1 1 2019 21 1 1 2019 31 1 2 1 11 1 2 2 11 1 2 2 21 1 2 2 31 1 2 3 11 1 2 3 21 1 2 3 31 1 2 3 41 1 2 3 5Sorry about english, not my native.

Viewing all articles
Browse latest Browse all 3145

Trending Articles