Data Model for Message Receiver
1. Physical Data Model

2. SQL Statements
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
Data Model for Message Receiver的更多相关文章
- EF,ADO.NET Entity Data Model简要的笔记
1. 新建一个项目,添加一个ADO.NET Entity Data Model的文件,此文件会生成所有的数据对象模型,如果是用vs2012生的话,在.Designer.cs里会出现“// Defaul ...
- Create Entity Data Model
http://www.entityframeworktutorial.net/EntityFramework5/create-dbcontext-in-entity-framework5.aspx 官 ...
- [ExtJs] ExtJs4.2 数据模型Ext.data.Model学习
Model代表应用程序管理的一些对象.例如,我们可能会为 我们想在系统中建模的现实世界中的一些物体像使用者.产品和汽车等定义一个Model.这些Model在 Ext.ModelManager中注册,被 ...
- [转]Creating an Entity Framework Data Model for an ASP.NET MVC Application (1 of 10)
本文转自:http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/creating-a ...
- Entity Framework Tutorial Basics(5):Create Entity Data Model
Create Entity Data Model: Here, we are going to create an Entity Data Model (EDM) for SchoolDB datab ...
- ExtJS教程(5)---Ext.data.Model之高级应用
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/jaune161/article/details/37391399 1.Model的数据验证 这里借助 ...
- HBase 数据模型(Data Model)
HBase Data Model--HBase 数据模型(翻译) 在HBase中,数据是存储在有行有列的表格中.这是与关系型数据库重复的术语,并不是有用的类比.相反,HBase可以被认为是一个多维度的 ...
- PowerDesigner从Physical Data Model转Excel
参考资料:http://www.cnblogs.com/hggc/archive/2013/10/15/3369857.html 由于有把ER图转Excel的需求,幸运地找到一个可用脚本,稍做修改完成 ...
- ExtJS笔记 Ext.data.Model
A Model represents some object that your application manages. For example, one might define a Model ...
随机推荐
- Manjaro (KDE)安装踩坑记录
1.如果双显卡无法安装系统可以进如BIOS屏蔽显卡后进入安装 2.如果安装kde版本后容易冻屏.死机,可以尝试安装闭源驱动 3.如果出现resolving time out 10000ms 这样的问题 ...
- linux 学习笔记 cpio命令
1 文件或目录打包 打包有如下多种情况 A>包含子目录打包 find /usr/lib -print /cpio -o >/uo/temp1.cpio 将/usr/lib目录下的文件与子目 ...
- Java笔记(十六)并发容器
并发容器 一.写时复制的List和Set CopyOnWrite即写时复制,或称写时拷贝,是解决并发问题的一种重要思路. 一)CopyOnWriteArrayList 该类实现了List接口,它的用法 ...
- python3.6.5 + selenium +VS Code 运行报错:Unable to find a matching set of capabilities的解决
在python3.6.5 + selenium +VS Code 环境中,在class的__init__ 方法初始化火狐浏览器时出现以下错误: 发生异常: selenium.common.except ...
- Tarjan求强连通分量 缩点
强连通分量的定义: 在一张有向图中,如果两个点u,v之间能相互到达则称这两个点u,v是强连通的,在这个基础上如果有向图G中的任意两个顶点都强连通,那么称图G是一个强连通图.有向非强连通图的极大强连通子 ...
- 向json对象中添加数组
// JSONArray jsonArray = new JSONArray();// for (int i = 0; i < list.size(); i++) {// JSONObject ...
- JsonServer服务环境搭建
在前后端分离的这种工作模式下,分工明确,各司其职.前端负责展示数据,后端提供数据.然而,在这种过程中对于接口的规范 需要提前制定好.例如根据规范提前模拟数据,这个时候就比较麻烦的.JsonServer ...
- Spring Boot集成JPA的Column注解命名字段无效的问题
偶然发现,Spring Boot集成jpa编写实体类的时候,默认使用的命名策略是下划线分隔的字段命名. Spring Boot版本:1.5.4.release 数据表: id int, userNam ...
- ES6_入门(3)_顶层对象属性
//顶层对象属性:在ES5中,顶层对象的属性与全局变量是等价的.以下代码中,为顶层对象的属性赋值与全局变量的赋值,是同一件事. window.a=10; console.log(window.a); ...
- Asp.Net HttpPostedFile和base64两种上传图片(文件)方式
之前上传图片基本都是用的HttpPostedFile方式获取图片,这次因为需求关系,要对准备上传的图片进行删除,最后提交的时候才去保存图片到服务器, 找了下资料,html5有个新的东西出来,js 里面 ...