惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
Cisco Talos Blog
Cisco Talos Blog
C
Check Point Blog
博客园_首页
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Martin Fowler
Martin Fowler
Recorded Future
Recorded Future
S
Security @ Cisco Blogs
L
LINUX DO - 最新话题
博客园 - 司徒正美
P
Privacy International News Feed
G
Google Developers Blog
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
C
Cybersecurity and Infrastructure Security Agency CISA
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
K
Kaspersky official blog
I
InfoQ
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Webroot Blog
Webroot Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
D
Docker
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
Microsoft Azure Blog
Microsoft Azure Blog
Spread Privacy
Spread Privacy
量子位
H
Hacker News: Front Page
Simon Willison's Weblog
Simon Willison's Weblog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
SecWiki News
SecWiki News
S
Security Affairs
Latest news
Latest news
人人都是产品经理
人人都是产品经理
C
CERT Recently Published Vulnerability Notes
S
Security Archives - TechRepublic
V
Visual Studio Blog
T
Troy Hunt's Blog
S
Secure Thoughts
F
Fortinet All Blogs
V
V2EX
The Register - Security
The Register - Security
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

博客园 - ok_008

解决GitHub加载和下载慢问题 mysql命令行爱好者必备工具mycli What is a Back Order mysql中实现字符串分割sp_split Down Payment 和 Deposit的差异 Select逻辑顺序图 排名趋势公式 批量备份数据库脚本(PowerShell版) 批量替换存储过程内容脚本sp_SqlReplace 生成建表脚本up_CreateTable Data Model for Certificate Implementation of Message Receiver SQL SERVER 批量生成编号 修改hosts文件 PHP-问题处理验证码无法显示出来 PHP-问题处理Fatal error: Uncaught Error: Call to undefined function mb_strlen() PHP-问题处理Fatal error: Uncaught Error: Call to undefined function simplexml_load_file() 10进制转33进制 PHP-生成缩略图和添加水印图-学习笔记 SQLServer地址搜索性能优化例子
Data Model for Message Receiver
ok_008 · 2017-02-25 · via 博客园 - ok_008
drop database MessageReceiver
go

/*==============================================================*/
/* Database: MessageReceiver                                    */
/*==============================================================*/
create database MessageReceiver
go

use MessageReceiver
go

/*==============================================================*/
/* Table: ReceiveMessage                                        */
/*==============================================================*/
create table ReceiveMessage (
   ID                   int                  identity,
   MessageType          nvarchar(200)        not null,
   Operation            smallint             not null,
   Content              nvarchar(max)        not null,
   IsCompleted          bit                  not null,
   TraceID              uniqueidentifier     not null default newid(),
   constraint PK_RECEIVEMESSAGE primary key (ID)
)
go

/*==============================================================*/
/* Table: ReceiveMessageLog                                     */
/*==============================================================*/
create table ReceiveMessageLog (
   ID                   int                  identity,
   ReceiveMessageID     int                  not null,
   LogTime              datetime             not null default getdate(),
   Remark               nvarchar(100)        null,
   constraint PK_RECEIVEMESSAGELOG primary key (ID)
)
go

/*==============================================================*/
/* Index: ix_ReceiveMessageLog_MsgID                            */
/*==============================================================*/
create index ix_ReceiveMessageLog_MsgID on ReceiveMessageLog (
ReceiveMessageID ASC
)
go

/*==============================================================*/
/* Table: SendMessage                                           */
/*==============================================================*/
create table SendMessage (
   ID                   int                  identity,
   MessageType          nvarchar(200)        not null,
   Operation            smallint             not null,
   Content              nvarchar(max)        not null,
   IsArrived            bit                  not null,
   TraceID              uniqueidentifier     not null default newid(),
   constraint PK_SENDMESSAGE primary key (ID)
)
go

/*==============================================================*/
/* Table: SendMessageLog                                        */
/*==============================================================*/
create table SendMessageLog (
   ID                   int                  identity,
   SendMessageID        int                  not null,
   LogTime              datetime             not null default getdate(),
   Remark               nvarchar(100)        null,
   constraint PK_SENDMESSAGELOG primary key (ID)
)
go

/*==============================================================*/
/* Index: ix_SendMessageLog_MsgID                               */
/*==============================================================*/
create index ix_SendMessageLog_MsgID on SendMessageLog (
SendMessageID ASC
)
go

alter table ReceiveMessageLog
   add constraint fk_ReceiveMessage_ReceiveMessageID foreign key (ReceiveMessageID)
      references ReceiveMessage (ID)
go

alter table SendMessageLog
   add constraint fk_SendMessageLog_SendMessageID foreign key (SendMessageID)
      references SendMessage (ID)
go


create procedure up_SendMessageToRemoteServer
as
declare @SendMessageID int,@MessageType nvarchar(200),@Operation smallint,@Content nvarchar(max),@TraceID uniqueidentifier
while(1=1)
begin
    set @SendMessageID=null
    select top(1)    @SendMessageID=ID,
                    @MessageType=MessageType,
                    @Operation=Operation,
                    @Content=Content,
                    @TraceID=TraceID
        from SendMessage a
        where a.IsArrived = 0
        order by a.ID
    if (@SendMessageID is null) break
    
    exec Server001.MessageReceiver.dbo.up_cReceiveMessageForRemoteServer 
            @MessageType =@MessageType, 
            @Operation = @Operation,
            @Content = @Content,
            @TraceID=@TraceID
 
    if (@@error <> 0) break
    exec up_cSendMessageLog 
        @SendMessageID = @SendMessageID,
        @Remark = N'发送',
        @IsArrived = 1
end
go


create procedure up_cReceiveMessage
(
    @MessageType nvarchar(200),
    @Operation smallint,
    @Content nvarchar(max)
)
as
begin try
    begin transaction
        declare @ReceiveMessageID int  
 
        insert into ReceiveMessage ( MessageType, Operation, Content,IsCompleted)
            values(@MessageType,@Operation,@Content,0)
        
        set @ReceiveMessageID=scope_identity()
        
        insert into ReceiveMessageLog ( ReceiveMessageID, Remark )
            values(@ReceiveMessageID,N'接收.')
 
    commit transaction  
end try
begin catch 
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go


create procedure up_cReceiveMessageForRemoteServer
(
    @MessageType nvarchar(200),
    @Operation smallint,
    @Content nvarchar(max),
    @TraceID uniqueidentifier
)
as
begin try
    begin transaction
        declare @ReceiveMessageID int  
 
        insert into ReceiveMessage ( MessageType, Operation, Content,IsCompleted,TraceID)
            values(@MessageType,@Operation,@Content,0,@TraceID)
        
        set @ReceiveMessageID=scope_identity()
        
        insert into ReceiveMessageLog ( ReceiveMessageID, Remark )
            values(@ReceiveMessageID,N'接收.')
 
    commit transaction  
end try
begin catch 
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go


create procedure up_cReceiveMessageLog
(
    @ReceiveMessageID int,
    @Remark nvarchar(100),
    @IsCompleted bit
)
as
begin try
    begin transaction        
 
        insert into ReceiveMessageLog ( ReceiveMessageID, Remark )
            values(@ReceiveMessageID,@Remark)
            
        update ReceiveMessage set IsCompleted=@IsCompleted where ID=@ReceiveMessageID
        
    commit transaction  
end try
begin catch 
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go


create procedure up_cSendMessage
(
    @MessageType nvarchar(200),
    @Operation smallint,
    @Content nvarchar(max)
)
as
begin try
    begin transaction
        declare @SendMessageID int  
 
        insert into SendMessage ( MessageType, Operation, Content,IsArrived)
            values(@MessageType,@Operation,@Content,0)
        
        set @SendMessageID=scope_identity()
        
        insert into SendMessageLog ( SendMessageID, Remark )
            values(@SendMessageID,N'接收.')
 
    commit transaction  
end try
begin catch 
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go


create procedure up_cSendMessageLog
(
    @SendMessageID int,
    @Remark nvarchar(100),
    @IsArrived bit
)
as
begin try
    begin transaction        
 
        insert into SendMessageLog ( SendMessageID, Remark )
            values(@SendMessageID,@Remark)
            
        update SendMessage set IsArrived=@IsArrived where ID=@SendMessageID
        
    commit transaction  
end try
begin catch 
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go


create procedure up_dReceiveMessageWithCompleted
as
set nocount on
begin try
    begin transaction
        declare @tb_del table(ID int)  
        insert into @tb_del(ID) select ID from ReceiveMessage where IsCompleted=1

        delete a from ReceiveMessageLog a where exists(select 1 from @tb_del x where x.ID=a.ReceiveMessageID)
        
        delete a from ReceiveMessage a where exists(select 1 from @tb_del x where x.ID=a.ID)
 
    commit transaction  
end try
begin catch 
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go


create procedure up_dSendMessageWithArrived
as
begin try
    begin transaction
    
        declare @tb_del table(ID int)  
        insert into @tb_del(ID) select ID from SendMessage where IsArrived=1
 
        delete a from SendMessageLog a where exists(select 1 from @tb_del x where x.ID=a.SendMessageID)
        
        delete a from SendMessage a where exists(select 1 from @tb_del x where x.ID=a.ID)

    commit transaction  
end try
begin catch 
    declare @error nvarchar(2048)=error_message()
    ;throw 50001 ,@error,1
    if (@@trancount >0) rollback transaction
end catch
go