Where to place the primary key

As far as I know, SQL Server 2008 will only allow one clustered index for each table. For the sake of this question, let me say that I have a list of user submitted stories containing the following columns.

ID (int, primary key)
Name (nvarchar)
Url (nvarchar)
UniqueName (nvarchar) This is url slug (blah-blah-blah)
CategoryID (int, FK in the category table)

In most cases, stories will never be queried by ID. Most queries will be executed either using a category identifier or using a unique name.

I am new to indexing, so I suggested that it would be better to place 2 non-clustered indexes in this table. One on UniqueName and one on CategoryID. After some reading about indexes, it seems that the clustered index on UniqueName will be very useful. Given UniqueName ... unique would it be beneficial to place the primary key in UniuqeName and get rid of the ID field? Regarding CategoryID, I assume that a non-clustered index will be very good.

Thanks.

+3
source share
5 answers

, id. , id. ( , , !).

, id, .

, , , , , , , . .

+3

"ID", , . . "" "ID", INT, , PK. , , ( ) INT nvarchar(). PK UniqueName.

+1

; , , , .

, , , .

+1

, . , , , , .

, , Highlander: !

, :

  • , , , BETWEEN, ;
  • , .

, , , , . , ( " " ). , , . , , .

"ID" -. , - .

+1

, . .

, . , , , , () . , , , , , , , - , , . ,

? . , , , . DBA Programmer , , , , . , , . , , , 100 000 , , , . , . 100 .

+1
source

Source: https://habr.com/ru/post/1703654/


All Articles