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 ...
随机推荐
- sql - 递归update
declare v_rlt ):; l_sql ); -- variable that contains a query l_c sys_refcursor; -- cursor variable(w ...
- C - Visible Trees HDU - 2841 -莫比乌斯函数-容斥
C - Visible Trees HDU - 2841 思路 :被挡住的那些点(x , y)肯定是 x 与 y不互质.能够由其他坐标的倍数表示,所以就转化成了求那些点 x,y互质 也就是在 1 - ...
- python 元类的简单解释
本文转自博客:http://www.cnblogs.com/piperck/p/5840443.html 作者:piperck python 类和元类(metaclass)的理解和简单运用 (一) p ...
- position 属性的值的比较
可取的四个值:static/relative/absolute/fixed static:默认值,top/right/bottom/left 无作用,z-index无效 relative:相对于原来的 ...
- jsonp 跨域 jsonp 发音
JSONP(JSON with Padding)是JSON的一种“使用模式” 可用于解决主流浏览器的跨域数据访问的问题. 由于同源策略, 一般来说位于 server1.example.com 的网页 ...
- Python应用【PDF处理-pypdf2】
概述 Python处理PDF文件需要安装相应的库:[PyPDF2]库 使用场景 工作中可能会涉及处理pdf文件,PyPDF2就是这样一个库, 使用它可以轻松的处理 pdf 文件,它提供了读.写.分割. ...
- git rewinding head to replay your work on top of it...
git fetch origin git reset --hard origin/<branch>
- 多角度对比 ES5与ES6的区别
ES5与ES6的对比不同点整理 本文关键词:ES6,javascript, 1.Default Parameters(默认参数) es6之前,定义默认参数的方法是在一个方法内部定义 var link ...
- NOIP不开心记(不开心的东西肯定不能给别人看!)
写在前面的.. noip之后一直很想写一下什么的.. 老师:这就是你逃晚自习来机房的原因?? Day 0 坐了好久的车来到GZ.. 年年都是GZ.. sb酒店垃圾的要死.. 路上都是杀马特.. 隔壁还 ...
- Android笔记--LinearLayout
LinearLayout 即线性布局,让子元素水平或垂直的排列在 layout中,子元素不会换行,当排到末尾时,剩下的组件将不会被显示出来. LinearLayout 常用的属性及方法: XML属性 ...