What is the use of primary key when non unique values can be entered in the database as mentioned in the answer provided in the link HERE ?
Asked
Active
Viewed 1,068 times
0
-
1Primary Key has to be unique. Other columns can be non unique.I don't know of any database where primary key can be non-unique. Please provide a verifiable code if you are able to create non-unique primary key. – Vaibhav Vishal Apr 22 '19 at 12:25
-
Check on the link I have provided. In the bottom of the verified answer you will see this line. – Ishita Agnihotri Apr 22 '19 at 12:28
-
Primary key is specified on table creation and could not be changed later. Despite the name, primary key is not unique. It just defines sort order of data to process range queries in optimal way. You could insert many rows with same value of primary key to a table. Check this on the link provided by me – Ishita Agnihotri Apr 22 '19 at 12:30
-
Yeah, apparently this database can have non-unique primary keys. Here is link I found after a quick google search which I hope explains the purpose of primary keys. https://medium.com/@f1yegor/clickhouse-primary-keys-2cf2a45d7324 – Vaibhav Vishal Apr 22 '19 at 12:34
-
Thanks, well that answer will seem bit more clear if you can put some light on what this article says – Ishita Agnihotri Apr 22 '19 at 12:44
-
This is too vague. What connection between "use of primary key" & "non unique values can be entered in the database" are you talking about? Why shouldn't PKs still be useful for what they are typically useful for? Also if you think what they call PKs are not PKs, then what do you mean by "PK" in the question (each time you use it, if you edit & use it more than once) & why isn't this just a case of somebody misusing a term? PS Clarify via edits, not comments. – philipxy Apr 22 '19 at 18:21
-
In the relational model a PK is a set of columns that is unique & contains no smaller set of columns that is unique. But in SQL "value" sometimes means a value & sometimes means a non-null value, & two values are "=" when they are equal and neither contains null, & two rows are "unique" when they are not SQL-=, & a "PK" is a set of columns whose subrows are SQL-unique & contain no nulls (& so are unique). Names are not descriptions, they denote things. You need to find out what a speaker is refering to when they use a word. – philipxy Apr 22 '19 at 18:58
-
@IshitaAgnihotri it's comment not an answer. If I write an answer I will explain it but I don't have enough expertise in this field to provide a good explanation, that's why I just posted a comment. – Vaibhav Vishal Apr 23 '19 at 06:02
1 Answers
2
It needs to forget about the world of relational databases and its constraints and imperatives a moment.
Primary Key in ClickHouse defines how data should be stored to get fast access to them and it doesn't serve to identify concrete 'entity'.
Other words, it describes the sparse index in sorted data - look at this article Primary Keys and Indexes in Queries.

vladimir
- 13,428
- 2
- 44
- 70