SQL Server 时区更改 [英] SQL Server Timezone Change
问题描述
我在同一个 SQL Server 上有 2 个数据库.是否可以在 PST 中使用一个而在 EST 中使用另一个?
I have 2 databases on the same SQL Server. Is it possible to have one in PST and the other in EST?
推荐答案
否,日期/时间源自运行 SQL Server 实例的计算机的操作系统.
No, The date/time is derived from the operating system of the computer on which the instance of SQL Server is running.
但是,您可以调用自定义 UDF 而不是 getdate(),然后在该 UDF 中更改时区.您还可以使用类似这样的内容为列分配默认值
You could however have a custom UDF that you would call instead of getdate() and then do the timezone change in that UDF. You can also assign default values to columns with something like this
CREATE TABLE Test (Val DATETIME DEFAULT dateadd(hh,-3,GETDATE()))
现在,当您执行插入操作时,它将使用默认值
Now when you do an insert it will use the default
INSERT test DEFAULT VALUES
SELECT * FROM test
....这当然不适用于更新,也有人可以更新该值
....this of course won't work on updates and also someone could update that value
如果您想使用 GMT,请使用 GETUTCDATE
If you want to use GMT then use GETUTCDATE
SELECT GETUTCDATE()
这篇关于SQL Server 时区更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!