[英]Datetime2 vs. String performance in SQL Server
What are the advantages of having a column of type datetime2
in SQL Server instead of a string? 在SQL Server中使用类型为
datetime2
的列而不是字符串有什么好处? Obviously strings are much more flexible. 显然,字符串要灵活得多。 Are there performance advantages while querying?
查询时有性能优势吗?
I'm designing a database where all entries are added via functions in another language and so there's no concern that a value not formatted like a date will be added to the column in question. 我正在设计一个数据库,其中所有条目都通过另一种语言的函数添加,因此不必担心未格式化为日期的值将被添加到所讨论的列中。 I'm considering making that column type string so I can more easily parse them when querying.
我正在考虑使该列类型为字符串,以便在查询时可以更轻松地解析它们。 When they are added to the database they are converted from Python's datetime format, which by convention has six digits of precision in fractions of seconds, to datetime2 format which has seven.
将它们添加到数据库后,它们会从Python的datetime格式(按惯例在几分之一秒内具有六位数的精度)转换为具有七位的datetime2格式。 Making the column be of type string will stop that from happening, but I'm worried about the performance issues that might come with not using datetime2.
将列设置为字符串类型将阻止这种情况的发生,但是我担心不使用datetime2可能会导致性能问题。
Datetime2 (and other date/time types): Datetime2(和其他日期/时间类型):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.