Sybase 中神秘的“时间戳"数据类型是什么? [英] What is the mysterious 'timestamp' datatype in Sybase?

查看:83
本文介绍了Sybase 中神秘的“时间戳"数据类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在工作中发现了我们 Sybase 数据库中的一个表,它使用了一个类型为时间戳"的列.如果我使用这种神秘的时间戳数据类型创建一个表

I recently discovered a table in our Sybase database at work that uses a column of a type 'timestamp'. If I create a table using this mysterious timestamp datatype like this

create table dropme (
    foo timestamp,  
    roo int null
)
insert into dropme (roo) values(123)
insert into dropme (roo) values(122)
insert into dropme (roo) values(121)
select * from dropme
go

我从select * from dropme"中得到以下信息:

I get the following from 'select * from dropme':

 foo                  roo
 -------------------- -----------
   0x000100000e1ce4ea         123
   0x000100000e1ce4ed         122
   0x000100000e1ce509         121

0x000100000e1ce4ea 对我来说看起来不太像时间戳.另外,我从sp_help timestamp"中看到了这个输出:

0x000100000e1ce4ea does not look very timestampy to me. Also, I see this output from 'sp_help timestamp':

 Type_name Storage_type Length Prec Scale Nulls Default_name Rule_name Access_Rule_name Identity
 --------- ------------ ------ ---- ----- ----- ------------ --------- ---------------- ----------
 timestamp varbinary         8 NULL  NULL     1 NULL         NULL      NULL                   NULL

我的问题如下

  1. 时间戳到底是什么?
  2. 它与时间或日期有任何关系吗?
  3. 我可以将其转换为日期时间吗?
  4. 如果它不是时间或日期,你用它做什么?

推荐答案

时间戳到底是什么?

时间戳数据类型定义为

varbinary(8) null

它与时间或日期有任何关系吗?

没有.名字选择不当.

我可以将其转换为日期时间吗?

没有

如果不是时间或日期,你用它做什么?

每次插入或更新带有时间戳列的行时,时间戳列都会自动更新.请注意,实际上有两种时间戳.TIMESTAMPCURRENT TIMESTAMP.不同之处在于 CURRENT TIMESTAMP 仅在插入时设置.

Each time a row with a timestamp column is inserted or updated, the timestamp column is updated automatically. Note that there are actually two kinds of timestamps. TIMESTAMP and CURRENT TIMESTAMP. The difference is that CURRENT TIMESTAMP is only set on insert.

Sybase 文档 停在那里让我想知道为什么 f*rainbow!*k 任何人都会使用数据类型时间戳.令人高兴的是,我发现了一些other 讨论 并推断其在实现乐观并发控制时使用.

The Sybase documentation stopped there leaving me wondering why the f*rainbow!*k anyone would ever use the datatype timestamp. Happily, I found some other discussions and deduced its used when implementing optimistic concurrency control.

并发控制是一种确保多个事务可以同时/大约同时运行并仍然产生正确数据的方法.乐观并发控制是一种并发控制方法,它假设多个事务可以完成而不相互干扰.即不需要锁定.维基百科描述了以下算法:

Concurrency control is a method of ensuring that multiple transactions can run at/around the same time and still result in correct data. Optimistic concurrency control is a concurrency control method that assumes multiple transactions can complete without interfering with each other. Ie no locking is required. Wikipedia describes the following algorithm:

  1. 记录交易开始时的日期/时间标记
  2. 读取/更新数据
  3. 检查其他事务是否修改了数据
  4. 提交或回滚

可以在此算法的第 1 步和第 3 步中使用 Sybase 的时间戳数据类型,而不是使用日期/时间.但在我看来,它并不像使用日期时间数据类型那样为您节省很多工作.我想它可能会表现得更好.

Sybase's timestamp datatype could be used in steps 1 and 3 of this algorithm instead of using a date/time. But it doesn't seem to me like it saves you much work over using a datetime datatype. I suppose it might perform better.

这篇关于Sybase 中神秘的“时间戳"数据类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆