First, remember that the database is designed to store facts and is designed to protect against bad data. Thus, the reason you do not want the user to enter 250 characters for the name is because the user will put all kinds of data there that are not the first name. They will put all their name, the size of their underwear, a novel about what they did last summer and so on. Thus, you want to strive to ensure that the data is as correct as possible. It is a mistake to assume that the application is the only protector against bad data. You want users to inform you that they had a problem with overlaying βWar on Peaceβ in this column.
Thus, the most important question is: "What is the most appropriate value of the stored data?" Ideally, you should use int and a check constraint to ensure that the values ββhave an appropriate range (e.g., greater than zero, less than a billion, etc.). Unfortunately, this is one of the weaknesses of MySQL: it does not comply with control restrictions. It just means that you have to integrate these integrity checks into triggers, which admittedly are more cumbersome.
Will the difference between int (4 bytes) be a noticeable difference from tinyint (1 byte)? Obviously, this depends on the amount of data. If you have no more than 10 lines, the answer will obviously not be. If you have 10 billion lines, the answer is obviously yes. However, IMO is premature optimization. It is much better to focus on ensuring correctness first.
In the text, you should ask if your data should support Chinese, Japanese or non-ANSI values ββ(i.e. use nvarchar or varchar)? Does this value mean a real world code, for example, a currency code or a bank code that has a specific specification?
source share