0

我需要有关架构更改的帮助。我有一个存储视频的视频表,我想知道ViewCount视频的实际情况。

这是我现在拥有的 Video 表架构:

CREATE TABLE dbo.VideoFiles(
VideoId     int IDENTITY(1, 1) PRIMARY KEY,
VideoTitle  nvarchar(64) NOT NULL,
VideoDescription nvarchar(2048),
PublishDate date,
Duration    time,
VideoUrl    nvarchar(256),
--ViewCount bigint,
UpdateTime  datetime default CURRENT_TIMESTAMP )

我可以有一个ViewCount在每次启动视频文件时增加 +1 的列,这看起来很简单。但是如何管理视频视图中的唯一性?

User1 view Video1 = Video1 Count =>1  
User2 view Video1 = Video1 Count =>2  
User1 view Video2 = Video2 Count =>1  
User1 view Video1 = Video1 Count =>2 (not increased as he already seen this video) 

谢谢,
普拉巴特

4

2 回答 2

1

Create a table

UserId int/UniqueIdentifier
VideoId Int
TimeOfView Datetime
SessionId int/UniqueIdentifier

This will help you.You will be able to give every answer from the business point. Like total view, view/day or unique visits/day. Similarly for week,months and year. More attributes can also be added for UserVisit.

于 2013-03-08T10:44:13.840 回答
1

所需的结构可能如下所示

CREATE TABLE [dbo].[ViedeoViews](
    [VideoID] [int] NOT NULL,
    [UserID] [int] NOT NULL,
 CONSTRAINT [PK_ViedeoViews] PRIMARY KEY CLUSTERED 
(
    [VideoID] ASC,
    [UserID] ASC
) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[ViedeoViews]  WITH CHECK ADD  CONSTRAINT [FK_ViedeoViews_VideoFiles] FOREIGN KEY([VideoID])
REFERENCES [dbo].[VideoFiles] ([VideoId])
GO

ALTER TABLE [dbo].[ViedeoViews] CHECK CONSTRAINT [FK_ViedeoViews_VideoFiles]
GO



Create View V_VideoFiles as
Select dbo.VideoFiles.*,(Select COUNT(*) from ViedeoViews vv where vv.VideoID=VideoFiles.VideoID) as ViewCount
from VideoFiles
于 2013-03-08T10:43:45.443 回答