-1

the question is about table2.id

Table1

id     -- Uniqueidentifier primary key   

Table2

id        -- Uniqueidentifier primary key
id_table1 -- Duplicate foreign key
value     -- varchar or other

The possible queries are :

select table1.id, table2.value 
from table1
inner join table2 ON table2.id_table1 = table1.id
where table1.id = 'foo'

or

select value
from table2
where table2.id_table1 = 'foo'

Are the performance changed with or without the existence of table2.id. Even if queries doesn't use it?

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
  • 1
    If these are all the queries, why bother adding the id column to the second table? just use the combination of `id_table1` and `value` as a primary key. If you already have a clustered unique index on that combination, it will not effect performance, only storage size. – Zohar Peled Jun 26 '16 at 08:44
  • http://stackoverflow.com/questions/45399/advantages-and-disadvantages-of-guid-uuid-database-keys – Ivan Starostin Jun 26 '16 at 09:43
  • @IvanStarostin While an interesting reading, the link you provided has no barring on the question itself. Whether the OP should use an int or guid is a totally different question then the one posted. – Zohar Peled Jun 26 '16 at 11:13
  • @ZoharPeled I know. At first I wanted to add _"you are asking wrong question"_ to my comment with that link. I guess he wouldn't ask anything without having troubles. And primary key column itself does not provide any troubles while `guid+clustered` combination _sometimes_ does. Not sure if idea of `guid+something` as clustered pk is much better. – Ivan Starostin Jun 26 '16 at 11:18

1 Answers1

0

I think the answer is yes. Having columns and indexes you will never use will have a negative performance impact although maybe not much depending on your exact situation.

I think though that what you really need is a better understanding of primary keys and indexes. In particular I recommend you research the debate on surrogate keys. You will find plenty of info on the topic.

Joe C
  • 3,925
  • 2
  • 11
  • 31