cs_Content_GetList
ALTER PROCEDURE [dbo].[cs_Content_GetList]
(
@SettingsID int
)
AS
SELECT
*
FROM
cs_Content c
WHERE
c.Hidden = 0 and c.SettingsID = @SettingsID
ORDER BY
c.LastModified DESC
/**//*获取不隐藏的信息*/
GO
ALTER PROCEDURE [dbo].[cs_Content_GetList]
(
@SettingsID int
)
AS
SELECT
*
FROM
cs_Content c
WHERE
c.Hidden = 0 and c.SettingsID = @SettingsID
ORDER BY
c.LastModified DESC
/**//*获取不隐藏的信息*/
GO
cs_Content_CreateUpdateDelete
ALTER PROCEDURE [dbo].cs_Content_CreateUpdateDelete
(
@ContentID int out,
@Action int,
@Name nvarchar(256),
@Title nvarchar(256),
@Body ntext,
@FormattedBody ntext,
@Hidden bit,
@UpdateDate bit,
@SettingsID int
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
-- CREATE
IF @Action = 0
BEGIN
-- first check that content name is not already in use
--检查内容名称是否被使用
IF EXISTS
(
SELECT
NULL
FROM
cs_Content
WHERE
Name = @Name and SettingsID = @SettingsID
)
/**//*如果存在则创建错误信息并返回*/
BEGIN
RAISERROR ( 'Content name in use', 16, 1)
RETURN
END
DECLARE @SortOrder int --声明排序类型
SELECT @SortOrder = coalesce(MAX(SortOrder) + 1, 1) FROM cs_Content where SettingsID = @SettingsID
/**//*COALESCE 返回其参数中第一个非空表达式。*/
-- Create a new content
--插入数据,即创建新内容.
INSERT INTO
cs_Content
(
Name,
Title,
Body,
FormattedBody,
Hidden,
SortOrder,
SettingsID
)
VALUES
(
@Name,
@Title,
@Body,
@FormattedBody,
@Hidden,
@SortOrder,
@SettingsID
)
SET @ContentID = SCOPE_IDENTITY()
/**//*SCOPE_IDENTITY返回插入到同一作用域中的 IDENTITY 列内的最后一个 IDENTITY 值。
一个作用域就是一个模块——存储过程、触发器、函数或批处理。因此,如果两个语句处
于同一个存储过程、函数或批处理中,则它们位于相同的作用域中。*/
END
-- UPDATE
ELSE IF @Action = 1
BEGIN
IF EXISTS
(
SELECT
NULL
FROM
cs_Content c
WHERE
c.Name = @Name
AND c.ContentID <> @ContentID and c.SettingsID = @SettingsID
)
/**//*如果活动为1,ID不同,但是存在相同名称的记录,则创建错误消息*/
BEGIN
RAISERROR ( 'Content name in use', 16, 1)
RETURN
END
IF EXISTS(SELECT NULL FROM cs_Content WHERE ContentID = @ContentID)
/**//*如果存在此ID的记录则更新此记录的内容*/
BEGIN
UPDATE
cs_Content
SET
Name = @Name,
Title = @Title,
Body = @Body,
FormattedBody = @FormattedBody
WHERE
ContentID = @ContentID and SettingsID = @SettingsID
IF @UpdateDate = 1 /**//*如果更新为真,运行更新存储过程,
此存储过程是更新最近操作时间的*/
EXEC cs_Content_UpdateDate @ContentID
END
END
-- DELETE
ELSE IF @Action = 2
BEGIN --如果为2,删除次记录
DELETE cs_Content WHERE ContentID = @ContentID and SettingsID = @SettingsID
END
GO
ALTER PROCEDURE [dbo].cs_Content_CreateUpdateDelete
(
@ContentID int out,
@Action int,
@Name nvarchar(256),
@Title nvarchar(256),
@Body ntext,
@FormattedBody ntext,
@Hidden bit,
@UpdateDate bit,
@SettingsID int
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
-- CREATE
IF @Action = 0
BEGIN
-- first check that content name is not already in use
--检查内容名称是否被使用
IF EXISTS
(
SELECT
NULL
FROM
cs_Content
WHERE
Name = @Name and SettingsID = @SettingsID
)
/**//*如果存在则创建错误信息并返回*/
BEGIN
RAISERROR ( 'Content name in use', 16, 1)
RETURN
END
DECLARE @SortOrder int --声明排序类型
SELECT @SortOrder = coalesce(MAX(SortOrder) + 1, 1) FROM cs_Content where SettingsID = @SettingsID
/**//*COALESCE 返回其参数中第一个非空表达式。*/
-- Create a new content
--插入数据,即创建新内容.
INSERT INTO
cs_Content
(
Name,
Title,
Body,
FormattedBody,
Hidden,
SortOrder,
SettingsID
)
VALUES
(
@Name,
@Title,
@Body,
@FormattedBody,
@Hidden,
@SortOrder,
@SettingsID
)
SET @ContentID = SCOPE_IDENTITY()
/**//*SCOPE_IDENTITY返回插入到同一作用域中的 IDENTITY 列内的最后一个 IDENTITY 值。
一个作用域就是一个模块——存储过程、触发器、函数或批处理。因此,如果两个语句处
于同一个存储过程、函数或批处理中,则它们位于相同的作用域中。*/
END
-- UPDATE
ELSE IF @Action = 1
BEGIN
IF EXISTS
(
SELECT
NULL
FROM
cs_Content c
WHERE
c.Name = @Name
AND c.ContentID <> @ContentID and c.SettingsID = @SettingsID
)
/**//*如果活动为1,ID不同,但是存在相同名称的记录,则创建错误消息*/
BEGIN
RAISERROR ( 'Content name in use', 16, 1)
RETURN
END
IF EXISTS(SELECT NULL FROM cs_Content WHERE ContentID = @ContentID)
/**//*如果存在此ID的记录则更新此记录的内容*/
BEGIN
UPDATE
cs_Content
SET
Name = @Name,
Title = @Title,
Body = @Body,
FormattedBody = @FormattedBody
WHERE
ContentID = @ContentID and SettingsID = @SettingsID
IF @UpdateDate = 1 /**//*如果更新为真,运行更新存储过程,
此存储过程是更新最近操作时间的*/
EXEC cs_Content_UpdateDate @ContentID
END
END
-- DELETE
ELSE IF @Action = 2
BEGIN --如果为2,删除次记录
DELETE cs_Content WHERE ContentID = @ContentID and SettingsID = @SettingsID
END
GO
cs_Content_Load
ALTER PROCEDURE [dbo].[cs_Content_Load]
(
@ContentID int,
@SettingsID int,
@Name nvarchar(256) = null
)
AS
IF(@ContentID > 0)
BEGIN
SELECT
[SettingsID], [ContentID], [Name], [Title], [Body], [FormattedBody], [LastModified], [SortOrder], [Hidden]
FROM
[dbo].[cs_Content]
WHERE
ContentID = @ContentID and SettingsID = @SettingsID
END
ELSE
BEGIN
SELECT
[SettingsID], [ContentID], [Name], [Title], [Body], [FormattedBody], [LastModified], [SortOrder], [Hidden]
FROM
[dbo].[cs_Content]
WHERE
[Name] = @Name and SettingsID = @SettingsID
/**//*如果ID大于0则一ID为条件查询,如果不大于0,则按名称为条件查询*/
END
GO
ALTER PROCEDURE [dbo].[cs_Content_Load]
(
@ContentID int,
@SettingsID int,
@Name nvarchar(256) = null
)
AS
IF(@ContentID > 0)
BEGIN
SELECT
[SettingsID], [ContentID], [Name], [Title], [Body], [FormattedBody], [LastModified], [SortOrder], [Hidden]
FROM
[dbo].[cs_Content]
WHERE
ContentID = @ContentID and SettingsID = @SettingsID
END
ELSE
BEGIN
SELECT
[SettingsID], [ContentID], [Name], [Title], [Body], [FormattedBody], [LastModified], [SortOrder], [Hidden]
FROM
[dbo].[cs_Content]
WHERE
[Name] = @Name and SettingsID = @SettingsID
/**//*如果ID大于0则一ID为条件查询,如果不大于0,则按名称为条件查询*/
END
GO