-
The difference between timestamp,datetime,int types in MySQL and their pros and cons int1. Occupies 4 bytes of 2. After indexing, the query is 3 faster. Conditional range searches can be used using BETWEEN4. You cannot use the time function provided by MySQL conclusion: it is suitable for data table datetime1 which need to make large time range query. Occupies 8 bytes of 2. Allowed to be null, the value can be customized and the system does not automatically modify its value. 3. Actual format storage (Just stores what are you having stored and retrieves the same thing which you have stored.) 4. is not related to time zone (It has nothing to deal with the TIMEZONE and Conversion.) 5. You cannot set a default value, so you must manually specify the value of the DateTime field to successfully insert the data in cases where null values are not allowed. 6. You can use the now () variable to automatically insert the current time of the system when specifying the value of a DateTime field. Conclusion: DateTime types are appropriate for recording the original creation time of the data, because no matter how you change the value of the other fields in the record, the value of the DateTime field does not change unless you manually change it. timestamp1. Occupies 4 bytes of 2. Null values are allowed, but values cannot be customized, so null values are meaningless. 3. The timestamp value cannot be earlier than 1970 or later than 2037. This indicates that a date, such as ' 1968-01-01 ', is valid for a datetime or date value but is not valid for the timestamp value, and is converted to 0 if assigned to such an object. 4. Values are saved in UTC (It stores the number of milliseconds) 5. Time zone conversion, the current time zone is converted when stored, and then converted back to the current time zone when retrieved. 6. The default value is Current_timestamp (), which is actually the current system time. 7. The database automatically modifies its value, so you do not need to specify the name of the timestamp field and the value of the timestamp field when inserting a record, you only need to add a timestamp field when you design the table, and the value of the field will automatically become the current system time when you insert it. 8. The timestamp value of the corresponding record is automatically updated to the current system time when the records in the table are modified at any later time. Conclusion: The timestamp type is suitable for recording the last modification time of the data as soon as you change theThe value of the other fields in the record, and the value of the timestamp field is automatically updated.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Differences and pros and cons of timestamp,datetime,int types in MySQL