![]() ![]() They even go so far as to say that PK data should be "meaningless": Sometimes, you may want use meaningful data, which considers being unique, for the primary keys e.g., social security number (SSN), vehicle identification number (VIN), email, and phone number. MySQL is far from unique on its handling of numeric data another page on Primary Keys in Oracle states that "primary keys typically are numeric because Oracle typically processes numbers faster than any other data types." And you should ensure sure that value ranges of the integer type for the primary key are sufficient for storing all possible rows that the table may have. Speaking about MySQL, states: Because MySQL works faster with integers, the data type of the primary key column should be the integer e.g., INT, BIGINT. There are plenty of reputable reference sites who echo that sentiment. This opinion was reinforced by my first employer, the Federal Government, who utilized numeric PKs, even if that meant adding a surrogate key. Say Aye for Numeric Typesīack when I was first learning about database development, I was instructed that numeric types are best for PKs because they are both faster and memory efficient. But that doesn't mean that one type may offer some advantages over the other. So long as your PK satisfies the above criteria, then you're good to go, as far as DB vendors are concerned. PK values should not be changed over time.A table can have only ONE primary key and in the table, this primary key can consist of single or multiple columns (fields).Primary keys must contain UNIQUE values, and cannot contain NULL values.It uniquely identifies each record in a table and posits that: What they do offer, are instructions regarding the PRIMARY KEY Constraint. Meanwhile, DB vendors themselves don't suggest one type over the other. ![]() Some sites state outright that numeric keys are almost always superior to character-based ones, while an equal number of sites promote the use of string types. The Great DebateĪdvice on what data type works best for primary keys (PKs) abounds on the Internet. Numeric data types include both exact numeric data types such as INTEGER, SMALLINT, DECIMAL, and NUMERIC, as well as the approximate numeric data types like FLOAT, REAL, and DOUBLE PRECISION. Other DB string data types include VARCHAR, BINARY, VARBINARY, BLOB, TEXT, ENUM, and SET. With regards to databases, single characters, represented by the CHAR type, are also grouped with Strings. For starters, the string data type is a generic IT term that traditionally refers a sequence of characters, either as a literal constant or as some kind of variable. String and Numeric Data Types in Relational Databasesīoth string and numeric nomenclatures are actually umbrella terms that encapsulate several different data types. Today's instalment will explore String and Numeric data types as Primary Keys in an effort to ascertain whether one is preferable to the other. In Part 1, we covered Natural and Surrogate Primary Keys and considered why one might choose one over the other. Welcome back to this series on choosing a Primary Key for relational databases. Choosing a Primary Key - Part 2 by Robert Gravelle String vs. ![]()
0 Comments
Leave a Reply. |