j9988 按日期生成自增號

2021-03-31 08:57:00 字數 2011 閱讀 2801

create table num_tb(d datetime,id int)

insert num_tb select '2004-01-01',1

create table tb(id varchar(20),name varchar(10))

create clustered index idx_clu_tb on tb(id)

gocreate trigger tri_tb on tb

instead of insert

asbegin

set nocount on

declare @i int,@id varchar(20),@j int

select @i=count(*) from inserted

begin tran

if exists(select 1 from num_tb where convert(char(8),d,112)=convert(char(8),getdate(),112))

begin

select @j=id from num_tb with(tablockx)

update num_tb with(tablockx) set id=id+@i

endelse

begin

update num_tb with(tablockx) set d=getdate(),id=@i

set @j=0

end***mit tran

select * into #t from inserted

update #t set id=convert(varchar(8),getdate(),112)+right('00000'+rtrim(@j),5),@j=@j+1

insert tb select * from #t

endgo

alter trigger tri_tb on tb

instead of insert

asbegin

set nocount on

declare @i int,@id varchar(20),@j int

select @i=count(*) from inserted

begin tran

update num_tb with(tablockx) set

id=(case when convert(char(8),d,112)=convert(char(8),getdate(),112)

then id+@i else @i end),

@j=(case when convert(char(8),d,112)=convert(char(8),getdate(),112) then id else 0 end),

d=getdate()

***mit tran

select * into #t from inserted

update #t set id=convert(varchar(8),getdate(),112)+right('00000'+rtrim(@j),5),@j=@j+1

insert tb select * from #t

endgo

--建立表

go     

--插入記錄測試

declare @i int

set @i=0

while @i<=10000

begin

insert into tb(name) values('張三')

insert into tb(name) select '張四'

union all select '張五'

union all select '張六'

union all select '張七'

union all select '張八'

union all select '張九'

union all select '張十'

set @i=@i+1

endgo

--刪除環境

drop table tb

log4j按業務切分不同的日誌檔案

public class loginfo public loginfo public loginfo string filesuffix,string message public string getfilesuffix public void setfilesuffix string files...

Log4j按級別輸出到不同檔案

之前曾寫過一篇帖子,是log4j按包路徑輸出到不同檔案。log4j按級別輸出到不同檔案,也類似。先看配置 set log levels log4j.rootlogger info,error,info log4j.logger.info info log4j.logger.error error 測...

Log4j按級別輸出到不同檔案

log4j.properties 檔案 log4j.logger.net.sf.hibernate.cache debug log4j.rootlogger error,portal log,shop log 這就比較煩,得到了我所不要想要的日誌資訊 源 public boolean isassev...

Log4j按級別輸出日誌到不同檔案配置

package com.liying.mango.common.interceptor import import org.apache.log4j.priority public override public boolean isassevereasthreshold priority prio...

Log4j按級別輸出日誌到不同檔案配置分析

log4j.rootlogger info,stdout,info,debug,error log4j.logger.info info log4j.logger.debug debug log4j.logger.error error而實際上這部分 解決不了按照log4j的級別檔案進行檔案輸出。配...