Should I use an automatically generated primary key if I just execute the lookup table?

I have a table with two varchar columns (Max)

Column 1      Column 2
-----------------------
URLRewitten   OriginalURL

its part of my url rewriting for asp.net website.

when url arrives. I check to see if it is in the table, if I use OriginalURL.

My question is: if all I do is query the table for the URLs and no other table in the database ever links to this table, do I need a dedicated primary key field? how is the auto number? will this make queries faster?

and also how to make the request work faster?

Edit: I have a unique restriction on URLRewitten.

Edit: how do I use this table.

  • Query when a new query appears .. Search URLRewitten to search OriginalURL
  • , OriginalURL, URL- URL-, .
  • URL- , .

thats , .. .

.

+3
7

? . . , , OriginalURL ( , URLRewritten InitialURL).

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

, , :

  • OriginalURL .
+12

... ...

.

UPDATE Rules SET OriginalURL = 'http://www.domain.com' WHERE ID = 1

--OR

INSERT INTO Rules SELECT OriginalUrl, NewUrl FROM Rules WHERE ID = 1

UPDATE Rules SET OriginalURL = "http://www.domain.com" WHERE OriginalURL = 'http://old.domain.com'

--OR

INSERT INTO Rules SELECT OriginalUrl, NewUrl FROM Rules WHERE OriginalURL = 'http://old.domain.com'

, OriginalURL, ,

+5

OriginalURL , , . , SQL-Server, RewrittenURL OrigionalURL " ", .

+2

:

select top 100 * from table order by idcolumn desc

, , .

+1

URLRewritten, , .

URLRewritten? , : (, URLRewritten primay?).

+1

, .

, :

  • , :(.
  • ,   , ,    -    .
  • To make this query faster we need to know more about this table and how to use it ...

In my opinion, each table should have an automatically generated primary key (i.e. an identifier in MSSQL).

I do not believe in unique natural keys.

0
source

Yes, there must be a primary key, because you can install INDEX on this primary key for quick access.

0
source

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


All Articles