- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Oracle 是否有与 SQL Server's RowVersion
类似的数据类型?
当您插入或更新行时,相应的版本列(类型为 RowVersion
)会自动更新。
Is a data type that exposes automatically generated, unique binarynumbers within a database. rowversion is generally used as a mechanismfor version-stamping table rows. The storage size is 8 bytes. Therowversion data type is just an incrementing number and does notpreserve a date or a time.
Each database has a counter that is incremented for each insert orupdate operation that is performed on a table that contains arowversion column within the database. This counter is the databaserowversion. This tracks a relative time within a database, not anactual time that can be associated with a clock. A table can have onlyone rowversion column. Every time that a row with a rowversion columnis modified or inserted, the incremented database rowversion value isinserted in the rowversion column.
You can use the rowversion column of a row to easily determine whetherany value in the row has changed since the last time it was read. Ifany change is made to the row, the rowversion value is updated. If nochange is made to the row, the rowversion value is the same as when itwas previously read.
You can add a rowversion column to a table to help maintain theintegrity of the database when multiple users are updating rows at thesame time. You may also want to know how many rows and which rows wereupdated without re-querying the table.
我们正在使用 Oracle 设计数据模型,并希望使用 Version 列来管理并发性。
我也想知道Oracle世界里是否有更好的方法。
最佳答案
Oracle 有 SCN(系统更改编号):http://docs.oracle.com/cd/E11882_01/server.112/e10713/transact.htm#CNCPT039
A system change number (SCN) is a logical, internal time stamp used by Oracle Database. SCNs order events that occur within the database, which is necessary to satisfy the ACID properties of a transaction. Oracle Database uses SCNs to mark the SCN before which all changes are known to be on disk so that recovery avoids applying unnecessary redo. The database also uses SCNs to mark the point at which no redo exists for a set of data so that recovery can stop.
SCNs occur in a monotonically increasing sequence. Oracle Database can use an SCN like a clock because an observed SCN indicates a logical point in time and repeated observations return equal or greater values. If one event has a lower SCN than another event, then it occurred at an earlier time with respect to the database. Several events may share the same SCN, which means that they occurred at the same time with respect to the database.
Every transaction has an SCN. For example, if a transaction updates a row, then the database records the SCN at which this update occurred. Other modifications in this transaction have the same SCN. When a transaction commits, the database records an SCN for this commit.
使用 ORA_ROWSCN 伪列检查行的当前 SCN:
http://docs.oracle.com/cd/B28359_01/server.111/b28286/pseudocolumns007.htm#SQLRF51145
一个例子:
SELECT ora_rowscn, t.* From test t;
演示 --> http://www.sqlfiddle.com/#!4/535bc/1
(在 SQLFiddle 上,显式提交显然不起作用 - 在真实数据库上,每次提交都会增加 SCN)。
“真实”数据库的示例:
CREATE TABLE test(
id int,
value int
);
INSERT INTO test VALUES(1,0);
COMMIT;
SELECT ora_rowscn, t.* FROM test t;
ORA_ROWSCN ID VALUE
---------- ---------- ----------
3160728 1 0
UPDATE test SET value = value + 1 WHERE id = 1;
COMMIT;
SELECT ora_rowscn, t.* FROM test t;
ORA_ROWSCN ID VALUE
---------- ---------- ----------
3161657 1 1
UPDATE test SET value = value + 1 WHERE id = 1;
COMMIT;
SELECT ora_rowscn, t.* FROM test t;
ORA_ROWSCN ID VALUE
---------- ---------- ----------
3161695 1 2
如果知道事务的SCN,我们可以使用闪回查询来获取该行的过去值:
http://docs.oracle.com/cd/B28359_01/appdev.111/b28424/adfns_flashback.htm#g1026131
示例:
SELECT t.*,
versions_startscn, versions_starttime,
versions_endscn, versions_endtime,
versions_xid, versions_operation
FROM test VERSIONS BETWEEN SCN MINVALUE AND MAXVALUE t;
ID VALUE VERSIONS_STARTSCN VERSIONS_STARTTIME VERSIONS_ENDSCN VERSIONS_ENDTIME VERSIONS_XID VERSIONS_OPERATION
---------- ---------- ----------------- ------------------- --------------- ------------------- ---------------- ------------------
1 2 3161695 13/12/10 08:19:39 06000300EA070000 U
1 1 3161657 13/12/10 08:18:39 3161695 13/12/10 08:19:39 06001200EA070000 U
1 0 3161657 13/12/10 08:18:39
SELECT t.*,
versions_startscn, versions_starttime,
versions_endscn, versions_endtime,
versions_xid, versions_operation
FROM test VERSIONS BETWEEN SCN 3161657 AND 3161657 t;
ID VALUE VERSIONS_STARTSCN VERSIONS_STARTTIME VERSIONS_ENDSCN VERSIONS_ENDTIME VERSIONS_XID VERSIONS_OPERATION
---------- ---------- ----------------- ------------------- --------------- ------------------- ---------------- ------------------
1 1 3161657 13/12/10 08:18:39 06001200EA070000 U
关于SQL Server : RowVersion equivalent in Oracle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20487657/
我有两个表(Users、DeletedUsers)和一个触发器 Users_Delete。删除用户记录时,我想将 ID 和最后一个 rowversion 值(在删除之前)存储在 DeletedUser
我不确定是否有必要。我有一个 sql server 2008 数据库,其中所有表都有一个时间戳列。最好将时间戳数据类型更改为 rowversion,以便可以轻松升级到 future 的 sql ser
我计划添加到数据库行版本中的大多数表以跟踪这些表中的更改。我知道添加它会影响查询的性能。 有谁知道它是否会稍微影响性能(慢几个百分点),或者我不应该向许多表添加行版本,因为它会使数据库变慢。 最佳答案
我有以下实体, public class PatientRegistry : BaseEntity { [Key, DatabaseGenerated(DatabaseGenerat
我正在创建将在我的应用程序中使用的默认并发策略。 我决定采用乐观策略。 我的所有实体都映射为Table per Type (TPT)(使用继承)。我很快了解到,在 Entity Framework 上
我的项目针对 SQL Server 2012 使用 EF(使用自跟踪模板测试版本 4,使用默认模板测试版本 5,所有数据库优先)。数据库表每个都有一个 rowversion ( timestamp )
我会保持这个简短而甜蜜。我正在尝试将 rowversion 类型的列添加到现有表中。我的想法是,通过将其添加为 NULL,现有行不会被标记时间戳,但可惜的是。如果是这种行为,那么在什么情况下该列会接受
我想知道比较表中的时间戳值以获取新更新/插入的行是否安全。 (例如 SQL Server RowVersion/Timestamp - Comparisons )。 在一个非常非常大/频繁更新的数据库
Oracle 是否有与 SQL Server's RowVersion 类似的数据类型? 当您插入或更新行时,相应的版本列(类型为 RowVersion)会自动更新。 MSDN says about
根据rowversion docs Each database has a counter that is incremented for each insert or update operatio
有谁知道是否有办法获取数据库的最大 RowVersion 值?我使用的数据库是SQL Server 2008。 谢谢。 最佳答案 您是否从@@DBTS 中查找,这是最后使用的值?变量名称仍然引用已弃用
在我的 C# 程序中,我不想使用字节数组,因此我将 rowversion 数据类型转换为 bigint: SELECT CAST([version] AS BIGINT) FROM [dbo].[my
我在我的 sql 中使用 Entity Framework 6,似乎 mysql 不支持行版本字节数组。任何帮助如何实现这一目标。 [Column(TypeName = "timestamp")] [
我使用的是 Miscrosoft SQL Server 2012,因为在此 article说: The timestamp syntax is deprecated. This feature wil
EF 默认为无并发控制(最后一次写入获胜),这允许丢失更新。 可以通过在 RowVersion 列上设置 ConcurrencyMode=Fixed 来明确配置强制开放式并发检查。 我们如何在所有表的
这个MSDN page状态: A nonnullable rowversion column is semantically equivalent to abinary(8) column. A nu
我尝试在 SQL Server 表上使用 ROWVERSION(或 TIMESTAMP)数据类型进行乐观并发控制。 我的表是使用 FluentMigrator 设置的,我不知道如何获取我需要的数据类型
我知道 RowVersion 列的值本身并没有用,只是每次更新行时它都会发生变化。但是,我想知道它们对于相对(不平等)比较是否有用。 如果我有一个带有 RowVersion 列的表,则满足以下任一条件
在更新期间支持 sql server rowversion 的最简单方法是什么? 我试过这个: db.UpdateOnly(u, f => new { f.Name, f.Description, f
我们正在使用 LINQ to SQL 和 WCF 作为新的中间层,并且我们正在使用数据传输对象通过网络进行传输,而不是使用实际的 LINQ 类。我将使用此处概述的一种或另一种方法 - Linq Tab
我是一名优秀的程序员,十分优秀!