--时间戳类型和bigint互相转化示例:byjinjazz
setnocounton
--申明3个时间戳
declare@timeFlag1bigint
declare@timeFlag2bigint
declare@timeFlag3bigint
--建立表,timestamp类型不需要字段名
createtabletest(timestamp,aint)
--插入1记录时间戳,@@dbts为数据库时间戳
insertintotestselectnull,1
set@timeFlag1=cast(@@dbtsasbigint)
--插入2记录时间戳
insertintotestselectnull,2
set@timeFlag2=cast(@@dbtsasbigint)
--更新3记录时间戳
updatetestseta=3wherea=2
set@timeFlag3=cast(@@dbtsasbigint)
--时间戳1的记录
select*fromtestwheretimestamp=cast(@timeFlag1asvarbinary(8))
--时间戳2的记录已经不存在了
select*fromtestwheretimestamp=cast(@timeFlag2asvarbinary(8))
--时间戳3的记录
select*fromtestwheretimestamp=cast(@timeFlag3asvarbinary(8))
--删除表
droptabletest
setnocountoff

/**//*--测试结果
timestampa
-----------------------------
0x000000000000B5531
timestampa
-----------------------------
timestampa
-----------------------------
0x000000000000B5553
*/
本文演示了如何在SQL中将时间戳类型与bigint类型进行互相转换,并通过具体实例展示了这一过程。首先声明了三个bigint变量来存储时间戳,接着创建了一个包含timestamp类型的表,并插入及更新了记录。
1450

被折叠的 条评论
为什么被折叠?



