In relational database design, a primary key can uniquely identify each row in a table. A primary key comprises a single column or a set of columns.
Questions tagged [primary-key]
641 questions
19
votes
5 answers
Why do primary keys have names of their own?
From a mathematical view, granted that a table has at most one primary key, it seems to be a shortsighted design decision to refer to primary keys by some arbitrary name instead of a simple table property.
As consequence to change a primary key from…
bernd_k
- 12,211
- 23
- 75
- 111
3
votes
3 answers
performance of multi field primary key or 'contrived' 'semi artificial' key
This is not a question regarding the benefits or otherwise of using an artificial auto increment key in any given table against using a multi-field 'primary key'. That discussion (or argument) can easily be found and decisions made by whoever would…
DaveM
- 133
- 1
- 6
2
votes
1 answer
Two tables with the same primary keys
Can two tables have the same primary keys?
For instance:
Revolucion for Monica
- 679
- 1
- 10
- 27
2
votes
1 answer
Difference between surrogate key(s) and composite key(s)?
I'm a beginner with databases and have been perplexed by the various definitions to distinguish these two. Various google searches have not fully clarified their differences. Please help explain them on a simple level.
tsp216
- 165
- 1
- 1
- 4
1
vote
2 answers
Update primary key
I want to update a primary key column, but the change should cascade to all other child tables where this primary key is used as foreign key.
Example: table1 has column "slug" as primary key. One row has the slug "foo" which should be "bar". The…
guettli
- 1,521
- 5
- 24
- 49
1
vote
1 answer
Trying to understand how an auto increment primary key is better than no primary key and some other primary key questions
I am trying to understand primary keys better, how to use them effectively in table design and in queries.
First, are the primary keys themselves used in WHERE clauses? For example, if I have a table of names and the primary key is setup as 'A' for…
cjones
- 353
- 1
- 6
- 12
1
vote
2 answers
Primary Keys for Address tables
I'm working on a database that stores address information. Each address has a Street, Number, Bus (as in the apartment they live in) and CityCode parameter. The CityCode parameter is a FK to the City table which has the postal code/zip code as PK…
Krowi
- 205
- 3
- 7
0
votes
2 answers
Does it matter if id (in TABLE ) starts from 0 or from 10000
Sorry for my incorrect terminology (as I don't know what to call that)..
does it matter (with regard to performance) if unique (index) key starts from 0 and from i.e. 100000 ?
For example, if I have
ID | Brand
----------------
1 | BMW
2 …
T.Todua
- 184
- 2
- 14
0
votes
0 answers
When should I create a primary key on multiple columns?
I'm interested to know in which case I should create a primary key on multiple columns and why ?
To be more specific about my question, I want to know what are the advantages and disadvantages of primary key on multiple columns in terms of…
Gary Olsson
- 101
- 1
-1
votes
1 answer
Two key attributes in an EER, what does it mean?
I'm currently drawing an EER diagram and stumbled across this problem:
Let's say I'm modeling a workplace where all employee's uniquely can be identified by their name (ie no employees share the exact same name) and their employee number. Is this a…
Samuel
- 1
-2
votes
1 answer
Why making ISBNs primary keys of the book table a poor choice?
Why making ISBNs primary keys of the book table a poor choice? I don't quite get what Carter have explained in lecture 1 - Relating, CS50 SQL. Although ISBNs are memory consuming, but they are worth being primary keys because they are unique for…
Đạt Phạm
- 11
- 1
-2
votes
1 answer
How does one make a invoice database using a budget from a contract?
The primary key of an invoice table is not the same as the primary key of the budget table. The budget has the same exact invoice descriptions as the invoice table but there isn’t really a primary key in the budget table that is a list of things…
Coo
- 101
- 5