Storing money in a decimal column – what precision and scale? [closed]

If you are looking for a one-size-fits-all, I’d suggest DECIMAL(19, 4) is a popular choice (a quick Google bears this out). I think this originates from the old VBA/Access/Jet Currency data type, being the first fixed point decimal type in the language; Decimal only came in ‘version 1.0’ style (i.e. not fully implemented) in VB6/VBA6/Jet … Read more

Surrogate vs. natural/business keys [closed]

Just a few reasons for using surrogate keys: Stability: Changing a key because of a business or natural need will negatively affect related tables. Surrogate keys rarely, if ever, need to be changed because there is no meaning tied to the value. Convention: Allows you to have a standardized Primary Key column naming convention rather … Read more

Is it better to use multiple databases with one schema each, or one database with multiple schemas? [closed]

A PostgreSQL “schema” is roughly the same as a MySQL “database”. Having many databases on a PostgreSQL installation can get problematic; having many schemas will work with no trouble. So you definitely want to go with one database and multiple schemas within that database.

Is there a good reason I see VARCHAR(255) used so often (as opposed to another length)?

255 is used because it’s the largest number of characters that can be counted with an 8-bit number. It maximizes the use of the 8-bit count, without frivolously requiring another whole byte to count the characters above 255. When used this way, VarChar only uses the number of bytes + 1 to store your text, … Read more

Remove Primary Key in MySQL

Without an index, maintaining an autoincrement column becomes too expensive, that’s why MySQL requires an autoincrement column to be a leftmost part of an index. You should remove the autoincrement property before dropping the key: ALTER TABLE user_customer_permission MODIFY id INT NOT NULL; ALTER TABLE user_customer_permission DROP PRIMARY KEY; Note that you have a composite … Read more