Ognacの雑感

木漏れ日々

目次

Blog 利用状況

書庫

ギャラリ

DBテーブルの更新日時

業務アプリでは、マスターに限らす、データべースのテーブルには、登録日や更新日の項目を設ける事が一般的です。
mSec単位まで保持可能にするのが普通で、楽観的排他の項目として使うこともあります。
SQL Serverならば、TimeStampで排他制御すれば楽なのですが、他のRDBでは該当項目がありません。
OracleのTimeStampは別ものです。RDB仕様として、下6から9ケタまで指定可能のように書かれてますが、OSの制約で、mSecまでしか格納できないようです。ということは、SqlSeverのDateTimeと違いは少ないです。
Timestampという言葉は、紛らわしいので困ります。Oracle文化圏の仕事をするとき嫌疑眼で見られますねぇ。
 
DB上の更新日は、DBサーバー上の時刻で、実際にDBにUPDATEされた時刻を格納したいので、 set x = sysdate()  などとするか、Default値として< sysdate()をセットします。
帳票に作成日時を印刷することもありますが、DBの整合性を考えて、印刷データを抽出した日時を印刷するものです。
 
しかし、設計者の心、子知らずなのか、PGさんは、クライアント日付を格納したり、印刷ルーチンが走る時点のクライアント日時を出力したりしてくれます。
更新日時なのに、YYYYMMDDの日単位しか格納しなかったりして、排他制御の役に立たなかったりします。
「プログラム仕様書に明記しないのが悪い」と言えばそうなのですが、共通仕様書には明記してます。それを個々に展開する時に、忘れるようですね。
業務仕様でなく、プログラムの基礎仕様なので、書いてなくても、どうすれはようのかは感じて欲しいものです。
オフショアの場合は、これは言ってはイケない事だそうです。このレベルよりも細かなレベルの仕様書を書いていると、「自作したほうが早い」衝動に駆られます。
 サーバー日付とクライアント日時は一致保障はないとか、データの日時の同一性などの知識は、「開発者たるもの持っているべきだ」とするのは高望みなんだろうか。

投稿日時 : 2008年9月1日 0:02

Feedback

# re: DBテーブルの更新日時 2008/09/01 0:10 シャノン

> OSの制約で、mSecまでしか格納できないようです。

Windows の制約?
いま仕事で使ってる Oracle on Linux は、点以下6桁まで持ってますよ。

# re: DBテーブルの更新日時 2008/09/01 3:02 なちゃ

最近のOracleはレコード単位でSCNだったか取れませんでしたっけ?
テーブル作成時に指定が必要だったとは思いますが。
ついでに使ったことないのでデメリットとかあるのかもよく知りませんが。

# re: DBテーブルの更新日時 2008/09/01 9:14 Ognac

コメント、ありがとうございます。
>いま仕事で使ってる Oracle on Linux は、点以下6桁まで持ってますよ。
Windowsの制約なのかなぁ。点4桁以下は 000でセットされます。WindowsのTimer刻みか msec単位だったか 150msec単位だったか、荒い刻みだった記憶があります。
高精度Timerは外付けの仕組なので、取り入れてないのかも。
高精度Timerがあったり、Linux/Oracleで可能なので、PC/AT仕様ではなさそうですね。


>最近のOracleはレコード単位でSCNだったか取れませんでしたっけ?
これって、Backupの相互の整合性など、File単位の比較と認識してました。
ServerとClientの設定時刻の差も認識するのだと、使えそうですね。
しかし、プログラムで、Client時刻をセットするソースだと無力な希ガス。

# re: DBテーブルの更新日時 2008/09/01 15:50 シャノン

開発になるとまた別の問題がありますね。
たとえば .NET Frameowrk の DateTime 型は…精度忘れたけど、そういうプログラム上の型と DB 上の型で精度が違うと、Select するときに桁数が減って、更新時に排他制御のつもりで Where 句につけると絶対一致しない、とか。

# re: DBテーブルの更新日時 2008/09/01 16:49 通りすがり

排他も含めその辺のシステムルールを末端のプログラマに直接書かせるのはどうかと思いますです。
カプセル化できる範疇ですからね。
DB等に依存しないという理由もありますが。

# re: DBテーブルの更新日時 2008/09/01 17:35 trapemiya

私も全テーブルに登録日時と更新日時を持たせ、トリガーでSQL Serverの方で設定するようにしています。登録日時と更新日時のないテーブルは考えられません。

# re: DBテーブルの更新日時 2008/09/01 19:05 Ognac

>更新時に排他制御のつもりで Where 句につけると絶対一致しない、とか。
>排他も含めその辺のシステムルールを末端のプログラマに直接書かせるのはどうかと思いますです。
>登録日時と更新日時のないテーブルは考えられません。

正に、皆様の仰る通りで、DB上の型を言語の型でどうのこうのするのは、工夫がいります。
ストアードでラップするのも手なんですが、ストアードネストの問題もあり、登録時に Sysdate()と登録端末/者/PRGをセットで更新させることもあります。
 DBのレコードの重要性は開発者たるもの熟知していて欲しいと思うのは無理があるのかなぁ。
「更新は、トランザクションを張って障害時は無かったことにする」と同レベルの知識.........個々に任せるのでなく、モジュール化して使わせるのが良いのか。 それは、開発スタイル設計者の課題ですね。
しかし、この辺りの細部(でもないか)の問題に気付かないプログラマってなんでしょうね。

# I am truly pleased to read this blog posts which contains lots of useful facts, thanks for providing such data. 2019/04/03 20:00 I am truly pleased to read this blog posts which c

I am truly pleased to read this blog posts which contains
lots of useful facts, thanks for providing such data.

# Helpful info. Fortunate me I discovered your web site unintentionally, and I am stunned why this accident did not came about earlier! I bookmarked it. 2019/04/07 6:11 Helpful info. Fortunate me I discovered your web s

Helpful info. Fortunate me I discovered your
web site unintentionally, and I am stunned why this accident did not came about earlier!

I bookmarked it.

# This article presents clear idea designed for the new visitors of blogging, that actually how to do blogging and site-building. 2019/07/15 15:49 This article presents clear idea designed for the

This article presents clear idea designed for the new visitors of blogging, that actually how to do blogging and
site-building.

# This article presents clear idea designed for the new visitors of blogging, that actually how to do blogging and site-building. 2019/07/15 15:50 This article presents clear idea designed for the

This article presents clear idea designed for the new visitors of blogging, that actually how to do blogging and
site-building.

# This article presents clear idea designed for the new visitors of blogging, that actually how to do blogging and site-building. 2019/07/15 15:51 This article presents clear idea designed for the

This article presents clear idea designed for the new visitors of blogging, that actually how to do blogging and
site-building.

# This article presents clear idea designed for the new visitors of blogging, that actually how to do blogging and site-building. 2019/07/15 15:52 This article presents clear idea designed for the

This article presents clear idea designed for the new visitors of blogging, that actually how to do blogging and
site-building.

# For newest information you have to go to see world-wide-web and on internet I found this web page as a most excellent site for newest updates. 2019/07/21 23:20 For newest information you have to go to see world

For newest information you have to go to see world-wide-web and on internet I
found this web page as a most excellent site for newest updates.

# Can you tell us more about this? I'd love to find out some additional information. 2019/07/24 16:05 Can you tell us more about this? I'd love to find

Can you tell us more about this? I'd love to find out some additional information.

# rpcSNBnBtuogrMEZTJV 2021/07/03 4:34 https://www.blogger.com/profile/060647091882378654

pretty handy stuff, overall I believe this is really worth a bookmark, thanks

# Illikebuisse xcxjz 2021/07/05 6:03 pharmaceptica.com

sildenafil 100 coupon https://www.pharmaceptica.com/

# Illikebuisse uegaq 2021/07/05 6:51 pharmaceptica.com

sildenafil australia paypal https://pharmaceptica.com/

# erectile tissue histology 2021/07/07 23:43 side effects of hydroxychloroquine 200 mg

hydrochloroquin https://plaquenilx.com/# hydroxychloroquine sulfate uses

# re: DB????????? 2021/07/24 13:37 plaquenil hydroxychloroquine sulfate

chloroquine cvs https://chloroquineorigin.com/# hydroxyquine side effects

# re: DB????????? 2021/08/09 9:41 hydroxychloroquine and chloroquine side effects

chloroquine https://chloroquineorigin.com/# side effects of hydroxychloroquine 200 mg

# qclihnrmsefs 2022/06/02 10:07 igueiocv

erythromycin for sinus infection http://erythromycinn.com/#

# generic hydroxychloroquine 2022/12/26 10:56 MorrisReaks

aralen online canada http://www.hydroxychloroquinex.com/#

タイトル
名前
Url
コメント