Sybase的timestamp类型

转自[url]http://action929.itpub.net/post/28194/306348[/url]
===========================================================作者: action929(http://action929.itpub.net)
发表于:2007.07.10 15:45
分类: Sybase
出处:http://action929.itpub.net/post/28194/306348
---------------------------------------------------------------今天有同事问我一个建表时候的错误:

1> create table aabbccddee( a timestamp,b timestamp)
2> go
Msg 2738, Level 16, State 2:
Server 'ipnet', Line 1:
A table can only have one timestamp column. Since table 'aabbccddee' already
has one, you can't add the column 'b'.

不能建2个时间类型?咋可能呢,上网查了一下

Sybase数据库中的timestamp为用户定义数据类型,它实际为varbinary(8)类型,但很多工程师把它当作date或time类型,这是错误的。其实在Sybase数据库中每一个数据库都会有一个全局timestamp,它被存放在dbtable内存结构中,它是一个顺序号,用于跟踪数据库中数据页的修改情况,主要被系统使用进行自身维护工作。用户不可以直接修改处理这种数据类型的数据,但使用DB-Library编程可以处理,特殊用户一般使用该数据类型来代替identity类型数据,需要注意的是,这个值只可以增大,不可以减小。

做了下测试:


1> create table test1(id int,times timestamp,times2 datetime)
2> go
1> insert into test1 values(1,null,getdate())
2> go
(1 row affected)
1> select * from test1
2> go
id times times2
----------- ------------------ --------------------------
1 0x0000000000faefd1 Jul 10 2007 3:43PM

(1 row affected)
1> insert into test1 values(2,0x11111,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> insert into test1 values(2,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.
Msg 213, Level 16, State 4:
Server 'ipnet', Line 1:
Insert error: column name or number of supplied values does not match table
definition.


1> create table test11(id int,id2 int identity)
2> go
1> insert into test11 values (null,1)
2> go
Msg 7743, Level 16, State 1:
Server 'ipnet', Line 1:
An explicit value for the identity field in table 'test11' can only be specified

in an insert statement when a field list is used.
1> insert into test11 values (2,1)
2> go
Msg 7743, Level 16, State 1:
Server 'ipnet', Line 1:
An explicit value for the identity field in table 'test11' can only be specified

in an insert statement when a field list is used.
1> insert into test11 values (1)
2> go
(1 row affected)
1> select * from test11
2> go
id id2
----------- -----------
1 1

(1 row affected)

总结下: identity和timestamp用起来差不多,区别在于

(1) identity 的列,不能出现在insert语句中,而timestamp必须出现,而且必须为null。

(2)identity的值,是在表一级唯一,timestamp的值是在数据库一级唯一。

(3)identity的类型可以自己指定,timestamp不可以

自己在ASE 12环境下测试了:

drop table testing;
create table testing(c1 int, ts timestamp, c2 int);
insert into testing(c1, ts , c2) values(112,'2009-08-21',123);

数据可以insert成功,只是报警告,为null时正常:
Server Message: Number 273, Severity 10
Server 'SYBAE', Line 1:
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.

insert into testing(c1 , c2) values(102,113);
select * from testing;

查询结果:
c1 ts c2
----------- -- -----------
112 0x0000000003078a06 123
102 0x0000000003078a19 113
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值