Tag Info

New answers tagged

5

Imagine you are out with a group of friends and the conversation turns to movies. Someone asks, "What did you think of 'The Three Musketeers'?" You respond, "Which one?" What additional information would you need to be absolutely certain you are both thinking of the same movie? The director's name? The production studio? The year it was released? One of the ...


4

Your table definition looks reasonable all over now. With all columns NOT NULL the UNIQUE constraint will work as expected - except for typos and minor differences in spelling, which may be rather common I am afraid. Consider @a_horse's comment. Alternative with functional unique index The other option would be a functional unique index (similar to what ...


3

The ID column has no advantage at all when it comes to the uniqueness you want/need to enforce. Uniqueness of whatever combination of attributes is never going to be enforced by adding a meaningless ID. Its "advantage" only shows when you ever get to the point where you'd need a new table that needs a foreign key to this one. In that case, and IF you have ...


7

I'll add one aspect to the existing excellent answers: Documentation. Often it is important to see what kinds of keys you can use to identify an entity. Any combination of unique columns is a candidate key. The primary key tends to be an especially useful concept in practice. Whether you enforce a key or not (you probably should) the documentation is ...


9

When you create a key in a database the DBMS engine enforces a uniqueness constraint on the key attributes. This serves at least three related purposes: Data integrity: duplicate data cannot be entered into key attributes. Any dependencies on the keys are therefore guaranteed. Identification: users are able to rely on keys as a means of identifying and ...


26

You are obviously suggesting that CONSTRAINTs in a database should be enforced by the application(s) that access that database? There are many reasons why this is a bad (bad, bad...) idea. 1) If you are building a "roll-your-own" constraint "engine" (i.e. within your application code), then you are merely emulating what Oracle/SQL ...



Top 50 recent answers are included