![](/Images/OutliningIndicators/ContractedBlock.gif)
cs_Favorite_GetByUserItem
1
ALTER procedure dbo.cs_Favorite_GetByUserItem
2
(
3
@SettingsID int,
4
@FavoriteType int,
5
@UserID int,
6
@ItemID int
7
)
8
AS
9
SET NOCOUNT ON
10![](/Images/OutliningIndicators/None.gif)
11![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*当 SET NOCOUNT 为 ON 时,不返回计数(表示受 Transact-SQL 语句影响的行数)。
12
当 SET NOCOUNT 为 OFF 时,返回计数。即使当 SET NOCOUNT 为 ON 时,
13
也更新 @@ROWCOUNT 函数。*/
14
SET Transaction Isolation Level Read UNCOMMITTED
15![](/Images/OutliningIndicators/None.gif)
16![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
17
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
18
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
19
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
20![](/Images/OutliningIndicators/None.gif)
21
-----------------------------------------------------------------------------
22![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//*同样是判断类型先,然后在执行操作.此条多了个拥有者的条件,其他还是照就.*/
23
-----------------------------------------------------------------------------
24![](/Images/OutliningIndicators/None.gif)
25
IF @FavoriteType = 1 -- Section
26![](/Images/OutliningIndicators/None.gif)
27
SELECT
28
F.FavoriteID,
29
F.OwnerID AS UserID,
30
F.SettingsID,
31
F.SectionID AS ItemID,
32
@FavoriteType AS FavoriteType,
33
F.ApplicationType
34
FROM
35
cs_FavoriteSections F
36
WHERE
37
F.OwnerID = @UserID AND
38
F.SectionID = @ItemID AND
39
F.SettingsID = @SettingsID
40![](/Images/OutliningIndicators/None.gif)
41
ELSE IF @FavoriteType = 2 -- User
42![](/Images/OutliningIndicators/None.gif)
43
SELECT
44
F.FavoriteID,
45
F.OwnerID AS UserID,
46
F.SettingsID,
47
F.UserID AS ItemID,
48
@FavoriteType AS FavoriteType,
49
F.ApplicationType
50
FROM
51
cs_FavoriteUsers F
52
WHERE
53
F.OwnerID = @UserID AND
54
F.UserID = @ItemID AND
55
F.SettingsID = @SettingsID
56![](/Images/OutliningIndicators/None.gif)
57
ELSE IF @FavoriteType = 4 -- Post
58![](/Images/OutliningIndicators/None.gif)
59
SELECT
60
F.FavoriteID,
61
F.OwnerID AS UserID,
62
F.SettingsID,
63
F.PostID AS ItemID,
64
@FavoriteType AS FavoriteType,
65
F.ApplicationType
66
FROM
67
cs_FavoritePosts F
68
WHERE
69
F.OwnerID = @UserID AND
70
F.PostID = @ItemID AND
71
F.SettingsID = @SettingsID
72![](/Images/OutliningIndicators/None.gif)
73![](/Images/OutliningIndicators/None.gif)
74
GO
posted on
2006-09-06 09:17
MainIsUsed
阅读(
231)
评论()
编辑
收藏
举报