The best answer is to point you back to your situation.
First, many people prefer sequences, as they are easy to generate and provide a single data type to navigate your joins. Additionally many shops require single column primary keys to assist further in code complexity.
Let's talk about the downsides:
Sequences:
When using b-tree indexes, sequences are generally inserted in ascending order, which can result in an "unbalanced tree" and cause less than perfect performance (on b-tree indexes) over time. Sometimes, people instead generate hashes or GUIDs to result in a more balanced tree.
Sequences can result in "hard to read" code when using "lookup tables", especially when values are hard coded in your database. Example: "where status_seq=1" is harder to read than "where status_id='ACTIVE'".
Downsides of using IDs:
Mixed data types can cause confusion. Sometimes they're numeric, sometimes they're varchar or char. Many ORMs can confuse those and leave off leading zeros causing errors in your results. IE 01234 != 1234, but your ORM may return 1234 instead of 01234.
Many people store ID's in human readable form, like "VALID", or state abbreviations. This can cause headaches in the long run, so even if you do use IDs on a table, you may want to steer clear from ever showing those IDs directly to your customer.
ID fields are much more likely to "need to change" in the future, than a sequence. Example: Let's say you have a country code table and a revolution takes place and a country code changes. Do you really want to go through the main table and all the foreign keys that reference it, putting in the new country code-- or living with the old country code, cause that's your choice. If you use a sequence in that case, you simply update other non-key columns in the base table and you're good to go.
Benefits:
Benefits of Sequences:
Sequences are by nature automatically generated. IDs aren't always. When adding records, do you really want a programmer or user naming an ID that cannot be easily changed? When you use sequences, there's rarely a need to renumber things, and the underlying human-readable data can be easily changed if a mistake is made.
As mentioned above, they're always a numeric datatype, and if used properly can assist in "navigating" you app (IE, usually only having to "pass around" one number to navigate your table structure)
When using an communicating between the DB and your programming language, you can count on being able to convert integers to integers without any weird data conversion issues.
IDs:
Primary benefit is code that's easier to read which we already explained above.
In summary, I think it's on a case, by case basis, depending on table and column usage. If you're going to use IDs, avoid the temptation to show the value to the user. If the table's not going to change and simply holds flags, or "enum" type data, then IDs can certainly help with code readability. Otherwise, sequences are often the better choice for maintainability of your data.
Some people choose GUIDs or IDs to help with index performance, but personally, if there's any loss in code readability or the code gets more complex, I'd spend some money on better hardware before I'd write more complex code-- as the benefit is miniscule.
Source: Oracle certified DBA (training on this exact subject), and 20+ years of experience working with developers and enterprise databases.
(col1,col2)
might be defined as key. Now you add a sequence and you got two unique constraints to implement. – Sheikdomidentity
columns as well asserial/bigserial
pseudotypes are based on sequences. So, if you use one of these, you automatically use sequences. – Luciusidentity
columns for compatibility with the SQL standard (and hence other RDBMSs). There's a good article about them here. If you're planning a migration from DB2, this sounds like the way to go. – Sanskritic