饿虎岗资源网 Design By www.oxmxm.com
删除一条留言信息会级联删除回复信息,这时我们需要用到事务,如下SQL
复制代码 代码如下:
ALTER PROCEDURE [dbo].[proc_tb_leaveword_delete]
(
@leavewordID INT,
@record TINYINT OUTPUT
)
AS
BEGIN
BEGIN TRY
BEGIN TRANSACTION
DELETE FROM tb_leavewordID WHERE leavewordID=@leavewordID
DELETE FROM tb_reply WHERE leavewordID=@leavewordID
SET @record=0 --成功
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
SET @record=-1 --失败
END CATCH
RETURN @record
END
删除一条新闻,一条新闻可能有多条留言,每条留言可能有回复信息,这时我们删除一条新闻的SQL如下
复制代码 代码如下:
ALTER PROCEDURE [dbo].[proc_tb_news_delete]
(
@newsID INT,
@record TINYINT OUTPUT
)
AS
BEGIN
DECLARE @leavewordCount INT --留言个数
DECLARE @delete_where VARCHAR(4000) --留言id字符,类似1,2,4,5,6
SET @leavewordCount=(SELECT ISNULL(COUNT(1),0) FROM tb_leaveword WHERE newsID=@newsID)
SET @delete_where=''
IF(@leavewordCount=0) --此条新闻无留言时
BEGIN TRY
DELETE FROM tb_news WHERE newsID=@newsID
SET @record=0 --成功
END TRY
BEGIN CATCH
SET @record=-1 --失败
END CATCH
ELSE IF(@leavewordCount>0) --此条新闻有留言时
----获取删除条件(start)----
DECLARE MY_CURSOR CURSOR
FOR SELECT leavewordID FROM tb_news WHERE newsID=@newsID
BEGIN
DECLARE @leavewordID INT
OPEN MY_CURSOR
FETCH NEXT FROM MY_CURSOR INTO @leavewordID
IF(@leavewordID IS NOT NULL)
SET @delete_where=@delete_where+CAST(@leavewordID AS VARCHAR(10))+','
WHILE(@@FETCH_STATUS<>-1)
BEGIN
SET @leavewordID=NULL
FETCH NEXT FROM MY_CURSOR INTO @leavewordID
IF(@leavewordID IS NOT NULL)
SET @delete_where=@delete_where+CAST(@leavewordID AS VARCHAR(10))+','
END
END
CLOSE MY_CURSOR
DEALLOCATE MY_CURSOR
SET @delete_where=SUBSTRING(@delete_where,1,LEN(@delete_where)-1)
----获取删除条件(end)----
BEGIN
BEGIN TRY
BEGIN TRANSACTION
DELETE FROM tb_news WHERE newsID=@newsID
EXECUTE('DELETE FROM tb_leaveword WHERE leavewordID IN('+@delete_where+')')
EXECUTE('DELETE FROM tb_reply WHERE leavewordID IN('+@delete_where+')')
SET @record=0 --成功
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
SET @record=-1 --失败
END CATCH
END
RETURN @record
END
删除一新闻类型时,可能此类型下有多条新闻,此条新闻下又有多条留言,留言下又有多条回复,依次级联删除,如下存储过程
复制代码 代码如下:
ALTER PROCEDURE [dbo].[proc_tb_news_type_delete]
(
@typeID INT,
@record TINYINT OUTPUT
)
AS
BEGIN
DECLARE @newsCount INT --此类新闻下的新闻个数
SET @newsCount=(SELECT ISNULL(COUNT(1),0) FROM tb_news WHERE typeID=@typeID)
IF(@newsCount=0) --此类型下无新闻
BEGIN TRY
DELETE FROM tb_news_type WHERE typeID=@typeID
SET @record=0 --成功
END TRY
BEGIN CATCH
SET @record=-1 --失败
END CATCH
ELSE IF(@newsCount>0) --此类型下有新闻
BEGIN TRY
BEGIN TRANSACTION
DECLARE MY_CURDOR CURSOR
FOR SELECT newsID FROM tb_news WHERE typeID=@typeID
BEGIN
DECLARE @newsID INT
OPEN MY_CURSOR
FETCH NEXT FROM MY_CURSOR INTO @newsID
IF(@newsID IS NOT NULL)
DELETE FROM tb_news_type WHERE typeID=@typeID
EXECUTE proc_tb_news_delete @newsID=@newsID --执行存储过程
WHILE(@@FETCH_STATUS<>-1)
BEGIN
SET @newsID=NULL
FETCH NEXT FROM MY_CURSOR INTO @newsID
IF(@newsID IS NOT NULL)
DELETE FROM tb_news_type WHERE typeID=@typeID
EXECUTE proc_tb_news_delete @newsID=@newsID --执行存储过程
END
END
CLOSE MY_CURSOR
DEALLOCATE MY_CURSOR
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
SET @record=-1 --失败
END CATCH
RETURN @record
END
当删除多条新闻类型时,我们需要把拼接好的类型id,例如:1,2,4,5,12,34,穿入存储过程,分割字符的SQL语句如下所示:
复制代码 代码如下:
DECLARE @A VARCHAR(5000)
DECLARE @i INT
SET @A='A,B,C,D,D,S,X,C,C,C,D,AAAA,DDDDDD,DEF,ERT,'
SET @i=CHARINDEX(',',@A)
WHILE @i>=1
BEGIN
PRINT LEFT(@A,@i-1)
SET @A=SUBSTRING(@A,@i+1,LEN(@A)-1)
SET @i=CHARINDEX(',',@A)
END
删除多条新闻类型SQL如下:
复制代码 代码如下:
ALTER PROCEDURE [dbo].[proc_tb_news_type_selects_delete]
(
@typeID_list VARCHAR(500),
@record TINYINT OUTPUT
)
AS
BEGIN
BEGIN TRY
BEGIN TRANSACTION
DECLARE @index INT
DECLARE @typeID INT
SET @typeID_list=RTRIM(LTRIM(@typeID_list))
SET @index=CHARINDEX(',',@typeID_list)
WHILE @index>=1
BEGIN
SET @typeID=CAST(LEFT(@typeID_list,@index-1) AS INT)
EXECUTE proc_tb_news_type_delete @typeID=@typeID
SET @typeID_list=SUBSTRING(@typeID_list,@index+1,LEN(@typeID_list)-1)
SET @index=CHARINDEX(',',@typeID_list)
END
COMMIT TRANSACTION
SET @record=0 --成功
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
SET @record=-1 --失败
END CATCH
RETURN @record
END
作者:cnblogs xu_happy_you
复制代码 代码如下:
ALTER PROCEDURE [dbo].[proc_tb_leaveword_delete]
(
@leavewordID INT,
@record TINYINT OUTPUT
)
AS
BEGIN
BEGIN TRY
BEGIN TRANSACTION
DELETE FROM tb_leavewordID WHERE leavewordID=@leavewordID
DELETE FROM tb_reply WHERE leavewordID=@leavewordID
SET @record=0 --成功
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
SET @record=-1 --失败
END CATCH
RETURN @record
END
删除一条新闻,一条新闻可能有多条留言,每条留言可能有回复信息,这时我们删除一条新闻的SQL如下
复制代码 代码如下:
ALTER PROCEDURE [dbo].[proc_tb_news_delete]
(
@newsID INT,
@record TINYINT OUTPUT
)
AS
BEGIN
DECLARE @leavewordCount INT --留言个数
DECLARE @delete_where VARCHAR(4000) --留言id字符,类似1,2,4,5,6
SET @leavewordCount=(SELECT ISNULL(COUNT(1),0) FROM tb_leaveword WHERE newsID=@newsID)
SET @delete_where=''
IF(@leavewordCount=0) --此条新闻无留言时
BEGIN TRY
DELETE FROM tb_news WHERE newsID=@newsID
SET @record=0 --成功
END TRY
BEGIN CATCH
SET @record=-1 --失败
END CATCH
ELSE IF(@leavewordCount>0) --此条新闻有留言时
----获取删除条件(start)----
DECLARE MY_CURSOR CURSOR
FOR SELECT leavewordID FROM tb_news WHERE newsID=@newsID
BEGIN
DECLARE @leavewordID INT
OPEN MY_CURSOR
FETCH NEXT FROM MY_CURSOR INTO @leavewordID
IF(@leavewordID IS NOT NULL)
SET @delete_where=@delete_where+CAST(@leavewordID AS VARCHAR(10))+','
WHILE(@@FETCH_STATUS<>-1)
BEGIN
SET @leavewordID=NULL
FETCH NEXT FROM MY_CURSOR INTO @leavewordID
IF(@leavewordID IS NOT NULL)
SET @delete_where=@delete_where+CAST(@leavewordID AS VARCHAR(10))+','
END
END
CLOSE MY_CURSOR
DEALLOCATE MY_CURSOR
SET @delete_where=SUBSTRING(@delete_where,1,LEN(@delete_where)-1)
----获取删除条件(end)----
BEGIN
BEGIN TRY
BEGIN TRANSACTION
DELETE FROM tb_news WHERE newsID=@newsID
EXECUTE('DELETE FROM tb_leaveword WHERE leavewordID IN('+@delete_where+')')
EXECUTE('DELETE FROM tb_reply WHERE leavewordID IN('+@delete_where+')')
SET @record=0 --成功
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
SET @record=-1 --失败
END CATCH
END
RETURN @record
END
删除一新闻类型时,可能此类型下有多条新闻,此条新闻下又有多条留言,留言下又有多条回复,依次级联删除,如下存储过程
复制代码 代码如下:
ALTER PROCEDURE [dbo].[proc_tb_news_type_delete]
(
@typeID INT,
@record TINYINT OUTPUT
)
AS
BEGIN
DECLARE @newsCount INT --此类新闻下的新闻个数
SET @newsCount=(SELECT ISNULL(COUNT(1),0) FROM tb_news WHERE typeID=@typeID)
IF(@newsCount=0) --此类型下无新闻
BEGIN TRY
DELETE FROM tb_news_type WHERE typeID=@typeID
SET @record=0 --成功
END TRY
BEGIN CATCH
SET @record=-1 --失败
END CATCH
ELSE IF(@newsCount>0) --此类型下有新闻
BEGIN TRY
BEGIN TRANSACTION
DECLARE MY_CURDOR CURSOR
FOR SELECT newsID FROM tb_news WHERE typeID=@typeID
BEGIN
DECLARE @newsID INT
OPEN MY_CURSOR
FETCH NEXT FROM MY_CURSOR INTO @newsID
IF(@newsID IS NOT NULL)
DELETE FROM tb_news_type WHERE typeID=@typeID
EXECUTE proc_tb_news_delete @newsID=@newsID --执行存储过程
WHILE(@@FETCH_STATUS<>-1)
BEGIN
SET @newsID=NULL
FETCH NEXT FROM MY_CURSOR INTO @newsID
IF(@newsID IS NOT NULL)
DELETE FROM tb_news_type WHERE typeID=@typeID
EXECUTE proc_tb_news_delete @newsID=@newsID --执行存储过程
END
END
CLOSE MY_CURSOR
DEALLOCATE MY_CURSOR
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
SET @record=-1 --失败
END CATCH
RETURN @record
END
当删除多条新闻类型时,我们需要把拼接好的类型id,例如:1,2,4,5,12,34,穿入存储过程,分割字符的SQL语句如下所示:
复制代码 代码如下:
DECLARE @A VARCHAR(5000)
DECLARE @i INT
SET @A='A,B,C,D,D,S,X,C,C,C,D,AAAA,DDDDDD,DEF,ERT,'
SET @i=CHARINDEX(',',@A)
WHILE @i>=1
BEGIN
PRINT LEFT(@A,@i-1)
SET @A=SUBSTRING(@A,@i+1,LEN(@A)-1)
SET @i=CHARINDEX(',',@A)
END
删除多条新闻类型SQL如下:
复制代码 代码如下:
ALTER PROCEDURE [dbo].[proc_tb_news_type_selects_delete]
(
@typeID_list VARCHAR(500),
@record TINYINT OUTPUT
)
AS
BEGIN
BEGIN TRY
BEGIN TRANSACTION
DECLARE @index INT
DECLARE @typeID INT
SET @typeID_list=RTRIM(LTRIM(@typeID_list))
SET @index=CHARINDEX(',',@typeID_list)
WHILE @index>=1
BEGIN
SET @typeID=CAST(LEFT(@typeID_list,@index-1) AS INT)
EXECUTE proc_tb_news_type_delete @typeID=@typeID
SET @typeID_list=SUBSTRING(@typeID_list,@index+1,LEN(@typeID_list)-1)
SET @index=CHARINDEX(',',@typeID_list)
END
COMMIT TRANSACTION
SET @record=0 --成功
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
SET @record=-1 --失败
END CATCH
RETURN @record
END
作者:cnblogs xu_happy_you
饿虎岗资源网 Design By www.oxmxm.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
饿虎岗资源网 Design By www.oxmxm.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月09日
2024年11月09日
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]