• <small id='ysEWi'></small><noframes id='ysEWi'>

    <legend id='ysEWi'><style id='ysEWi'><dir id='ysEWi'><q id='ysEWi'></q></dir></style></legend>
      <bdo id='ysEWi'></bdo><ul id='ysEWi'></ul>

      <i id='ysEWi'><tr id='ysEWi'><dt id='ysEWi'><q id='ysEWi'><span id='ysEWi'><b id='ysEWi'><form id='ysEWi'><ins id='ysEWi'></ins><ul id='ysEWi'></ul><sub id='ysEWi'></sub></form><legend id='ysEWi'></legend><bdo id='ysEWi'><pre id='ysEWi'><center id='ysEWi'></center></pre></bdo></b><th id='ysEWi'></th></span></q></dt></tr></i><div id='ysEWi'><tfoot id='ysEWi'></tfoot><dl id='ysEWi'><fieldset id='ysEWi'></fieldset></dl></div>
        <tfoot id='ysEWi'></tfoot>

        如何修改现有表以添加时区

        时间:2023-08-21
        <i id='pDnuW'><tr id='pDnuW'><dt id='pDnuW'><q id='pDnuW'><span id='pDnuW'><b id='pDnuW'><form id='pDnuW'><ins id='pDnuW'></ins><ul id='pDnuW'></ul><sub id='pDnuW'></sub></form><legend id='pDnuW'></legend><bdo id='pDnuW'><pre id='pDnuW'><center id='pDnuW'></center></pre></bdo></b><th id='pDnuW'></th></span></q></dt></tr></i><div id='pDnuW'><tfoot id='pDnuW'></tfoot><dl id='pDnuW'><fieldset id='pDnuW'></fieldset></dl></div>
            <tbody id='pDnuW'></tbody>

            <small id='pDnuW'></small><noframes id='pDnuW'>

            1. <tfoot id='pDnuW'></tfoot>

                  <bdo id='pDnuW'></bdo><ul id='pDnuW'></ul>

                  <legend id='pDnuW'><style id='pDnuW'><dir id='pDnuW'><q id='pDnuW'></q></dir></style></legend>
                  本文介绍了如何修改现有表以添加时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有一个包含 500 多个表的大型应用程序,我必须将应用程序转换为时区感知(当前应用程序使用 new java.util.Date(), GETDATE() 与服务器的时区).即不支持任何时区.

                  I have a large application with 500+ tables, I have to convert the application to be timezone aware (currently application uses new java.util.Date(), GETDATE() with server's timezone). i.e. no timezone support whatsoever.

                  为了简化开发,我已将此任务分为几个步骤,我确定的第一个步骤是根据服务器的时区将所有旧日期更改为 UTC.(主要位于一个时区,所以这是我最好的猜测)

                  I have organised this task into a few steps so as to ease development, my first identified step is to change all old dates to UTC based on the server's timezone. (mostly located in one timezone, so this is my best guess)

                  接下来,我需要修改数据库和应用程序代码以使用时区名称和偏移量以 UTC 格式保存所有日期,这就是我的问题所在...

                  Next, I need to modify the database and application code to save all dates in UTC with a timezone name and offset, this is where my problem comes in...

                  我将如何修改数据库/表以很好地支持这一点?

                  How would i go about modifying the database/tables to support this in a good manner?

                  我的想法是:

                  1. 对于表中的每个日期/时间列,添加两个额外的列(用于 tz-name 和偏移量)
                    • 感觉很糟糕的设计
                  • 虽然更便携,但这张表最终将包含数百万行,因为它是将整个数据库的日期塞进一张表中
                  • 虽然不可移植,但这似乎是最好的(关系)选项

                  有人有其他想法或最佳实践吗?

                  Does anyone have any other ideas or best-practices?

                  推荐答案

                  根据我的经验,您通常应该将数据存储为 UTC,并将相关时区放在单独的列中.拥有一张时区表并存储时区键是关系数据库的合理做法.

                  In my experience you should generally store the data as UTC, with the relevant timezone in a separate column. Having a table for timezones and storing the timezone key is the reasonable thing to do with a relational database.

                  不过,在这种情况下,您的所有数据都已在当地时间,因此在这种情况下,您可以将当地时间存储在时间列中,并为时区添加一列.这样您就不必转换数据库中已有的日期.

                  In this case though, all your data is in a local time already, so in this case you can store the local time in the time column, and add a column for the time zone. That way you don't have to convert the dates that are already in the database.

                  没有必要存储偏移量,除非您最终注意到从日期和区域转换为偏移量太耗时.

                  Storing offset is not necessary, unless you end up noticing that converting from date and zone to offset is too time-consuming.

                  这篇关于如何修改现有表以添加时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在数据库中存储照片参考的最有效方法 下一篇:将行从 TableA 移动到 Table-Archive

                  相关文章

                  最新文章

                    <bdo id='eoa0n'></bdo><ul id='eoa0n'></ul>
                  <i id='eoa0n'><tr id='eoa0n'><dt id='eoa0n'><q id='eoa0n'><span id='eoa0n'><b id='eoa0n'><form id='eoa0n'><ins id='eoa0n'></ins><ul id='eoa0n'></ul><sub id='eoa0n'></sub></form><legend id='eoa0n'></legend><bdo id='eoa0n'><pre id='eoa0n'><center id='eoa0n'></center></pre></bdo></b><th id='eoa0n'></th></span></q></dt></tr></i><div id='eoa0n'><tfoot id='eoa0n'></tfoot><dl id='eoa0n'><fieldset id='eoa0n'></fieldset></dl></div>

                  <small id='eoa0n'></small><noframes id='eoa0n'>

                  1. <tfoot id='eoa0n'></tfoot>

                    1. <legend id='eoa0n'><style id='eoa0n'><dir id='eoa0n'><q id='eoa0n'></q></dir></style></legend>