Sybase内置数据类型Timestamp

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a19881029/article/details/38085257
1> select @@version
2> go
                                                                                                                                                                                                                                                                 
 --------------------------------------------------------------------------------
 Adaptive Server Enterprise/15.5/EBF 18164 SMP ESD#2/P/x86_64/Enterprise Linux/a
         sear155/2514/64-bit/FBO/Wed Aug 25 11:17:26 2010                                                                                                                                 

(1 row affected)

一张表中只能创建一个Timestamp类型字段:

1> create table test(t1 timestamp, t2 timestamp)
2> go
Msg 2738, Level 16, State 2:
Server 'SYBASE', Line 1:
A table can only have one timestamp column.  Since table 'test' already has one,
you can't add the column 't2'.
1> create table test(id int, date date, time timestamp)
2> go

Sybase中的Timestamp不是一种时间类型(这点和Oracle、MySQL不一样):

1> insert into test values(1, getdate(), getdate())
2> go
Warning: A non-null value cannot be inserted into a TIMESTAMP column by the
user. The database timestamp value has been inserted into the TIMESTAMP field
instead.
(1 row affected)
1> select * from test
2> go
 id          date         time               
 ----------- ------------ ------------------ 
           1  Jul 24 2014 0x00000000000a8b75 

(1 row affected)

Timestamp类型字段是一个顺序号(只增不减),本质上算是一种“戳”,用来记录跟踪数据库中数据页的修改情况(主要被系统使用进行自身维护工作,用户不可以直接修改、处理这种数据类型的数据):

1> update test set date = getdate()
2> go
(1 row affected)
1> select * from test
2> go
 id          date         time               
 ----------- ------------ ------------------ 
           1  Jul 24 2014 0x00000000000a8bdb 

(1 row affected)

插入的时候不指定具体值,或者插入null,数据库都会在不报错的情况下完成该字段的填充:

1> insert into test values(2, getdate(), null)
2> go
(1 row affected)
1> insert into test(id, date) values(3, getdate())
2> go
(1 row affected)
1> select * from test
2> go
 id          date         time               
 ----------- ------------ ------------------ 
           1  Jul 24 2014 0x00000000000a8bdb 
           2  Jul 24 2014 0x00000000000a8bec 
           3  Jul 24 2014 0x00000000000a8bf5 

(3 rows affected)

 

展开阅读全文

没有更多推荐了,返回首页