LiCongMingDeShujuku / Basic-Way-To-Create-ModifedDate-Column-In-SQL

关于在SQL中创建ModifedDate列的基本方法

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CLEVER DATA GIT REPO

关于在SQL中创建ModifedDate列的基本方法

Basic Way To Create ModifedDate Column In SQL

发布-日期: 2018年01月19日 (评论)

#

Contents

中文

这是为一些表创建[ModifedDate]列的基本方法。通常,每当你创建一个会进行各种更新和修改的表时,你需要为[CreateDate]和[ModifedDate]添加经典列。

在这个例子中,我正在调用的基本表[Standard_Rules_00]基本上是可以存储我的一些自定义构建或修改脚本的地方。

English

Here’s a basic way to create the [ModifedDate] column for some of your tables. Often times whenever you create a table that will undergo various updates and modifications; you’ll find yourself wanting to add the classic columns for [CreateDate] and [ModifedDate]. In this example; I have a basic table I’m calling [Standard_Rules_00] which is basically a place where I can store some of my custom build, or modification scripts.


Logic

use [compliance];
set nocount on
 
create table [STANDARD_RULES_00]
(
    [lineid]    	int identity(1,1)
,   [createdate]    datetime null
,   [statements]    varchar(max)
,   [modifieddate]  datetime null
,   [description]   varchar(max)
)
go
 
create trigger trig_post_insert
on [dbo].[STANDARD_RULES_00]
after insert
as
begin
    update [dbo].[STANDARD_RULES_00]
    set [createdate] = getdate()
    from dbo.[STANDARD_RULES_00] sr
    where exists (select 1 from inserted i where i.[lineid] = sr.[lineid]);
end
go
 
create trigger trig_post_update
on [dbo].[STANDARD_RULES_00]
after update
as
begin
    update [dbo].[standard_rules_00]
    set [modifieddate] = getdate()
    from dbo.[STANDARD_RULES_00] sr
    where exists (select 1 from inserted i where i.[lineid] = sr.[lineid]);
end
go

WorksEveryTime

Build-Info

Build Quality Build History
Build-Status
Coverage
Nuget
Build history

Author

  • 李聪明的数据库 Lee's Clever Data
  • Mike的数据库宝典 Mikes Database Collection
  • 李聪明的数据库 "Lee Songming"

Gist Twitter Wordpress


License

LicenseCCSA

Lee Songming

About

关于在SQL中创建ModifedDate列的基本方法


Languages

Language:TSQL 100.0%