SQLServer站內信的資料庫的設計

來源:互聯網
上載者:User

現有兩張表:

表一名:Message

ID:編號;

SendID:寄件者編號;

RecID:接受者編號(如為0,則接受者為所有人);

MessageID:站內信編號;

Statue:站內信的查看狀態,

ReadTime:讀取時間;

表二名:MessageText 

ID:編號;

Message:站內信的內容;

PDate:站內信發送時間;

表三名:ReadGlobalMessage

ID:群訊息編號

GlobalID:群訊息ID與Message中的messageid相對應;

USerID:使用者編號;

ReadTime:讀取時間;

Status:群訊息狀態(只是是否存在);

其中兩個編號為自動成長,Message中的MessageID為MessageText表的外鍵,對應於MessageText中的編號ID,

管理員群發站內信:

ALTER PROCEDURE dbo.newmsgsingle @sendid int, @recid int, @title nvarchar(50), @message nvarchar(50)ASinsert into messgetext values(@title,@message,getdate())insert into message values(@sendid,@recid,@@identity,'',0)RETURN

這裡的recid設為0,表示接受者為所有人;

下面用到的Msg為視圖:

SELECT dbo.Message.SendID, dbo.Message.RecID, dbo.Message.MessageID,       dbo.Message.ReadTime, dbo.Message.Status, dbo.MessgeText.Title,       dbo.MessgeText.Message, dbo.MessgeText.CreateTimeFROM dbo.Message INNER JOIN      dbo.MessgeText ON dbo.Message.MessageID = dbo.MessgeText.ID

顯示未查看短訊息的數目:

ALTER PROCEDURE dbo.getmsgcount@userid intASSELECT  count(MessageID)FROM MsgWHERE (MessageID NOT IN          (SELECT GlobalID         FROM ReadGlobalMessage         WHERE (UserID =@userid))) AND (Status = 0) AND (RecID =@userid OR      RecID = 0)RETURN

擷取未讀短訊息的資料:

ALTER PROCEDURE dbo.getunreadmsglist@userid int ASSELECT *FROM MsgWHERE (MessageID NOT IN          (SELECT GlobalID         FROM ReadGlobalMessage         WHERE (UserID = @userid))) AND (Status = 0) AND (RecID =@userid OR      RecID = 0)RETURN

查看所有短訊息(包括未讀的已讀的,只要沒有被使用者數刪除就擷取)

ALTER PROCEDURE dbo.getallmsg@userid int ASSELECT *FROM MsgWHERE (MessageID NOT IN          (SELECT GlobalID         FROM ReadGlobalMessage         WHERE (UserID = @userid and status=0))) AND (RecID =@userid) OR      (RecID = 0)RETURN

查看短訊息的詳細內容:

ALTER PROCEDURE dbo.getmsgdetails@msgid int,@userid intASdeclare @temprecid intselect @temprecid=recid from message where id=@msgidif @temprecid!=0begin   select * from messgetext where id=@msgid   update message set status=1,readtime=getdate() where messageid=@msgid and recid=@userid end else begin    select * from messgetext where id=@msgid    insert into readglobalmessage values(@msgid,@userid,getdate(),default)  endRETURN

使用者查看短訊息內容:使用者進入短訊息介面之後,點擊其中一條短訊息,根據短訊息編號擷取具體的短訊息內容;如果該短訊息為群訊息則在ReadGlobalMessage中插入資料,如果為點對點的訊息則

更新Message表中的資料如Statue以及Readtime;

擷取

使用者之間發送短訊息和管理群發短訊息類似;

關鍵點:擷取剛剛添加的自動成長列的值:@@IDENTITY;

站內信執行個體下載

參考部落格1

參考部落格2

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.