各位帮忙看下这个sql语句的问题
sql语句如下:
--开始事务
begin transaction
declare @errorsum int ,@usersid int,@sectionid int,@topiccounts int
select @sectionid=sid from bbssection where sname='.NET技术'
set @errorsum =@errorsum+@@error
select @usersid=uid from bbsusers where uname='sky'
print @usersid
set @errorsum =@errorsum+@@error
insert into bbstopic (tsid,tuid,ttopic,tcontents)
values (@sectionid,@usersid,'小弟请问.NET配置问题','.NET配置具体需要那些环境啊,我的页面怎么跑不起来呢?')
set @errorsum =@errorsum+@@error
update bbssection set stopiccount=stopiccount+1 where sid= @sectionid
set @errorsum =@errorsum+@@error
select * from bbssection where sname='.NET技术'
set @errorsum =@errorsum+@@error
set @topiccounts=@@rowcount
if @topiccounts=1
begin
update bbsusers set upoint=upoint+100 where uid=@usersid
end
else
begin
update bbsusers set upoint=upoint+50 where uid=@usersid
end
update bbsusers
set uclass=case
when upoint <500 then 1
when upoint between 500 and 1000 then 2
when upoint between 1001 and 2000 then 3
when upoint between 2001 and 4000 then 4
when upoint between 4001 and 5000 then 5
else 6
end
set @errorsum =@errorsum+@@error
print 'sky发布的帖子新是:'
select 板块=tsid,主题=ttopic,帖子内容=tcontents,发帖时间=ttime from bbstopic where tuid=@usersid
set @errorsum =@errorsum+@@error
if @errorsum <>0
begin
print '更新失败,回滚事务'
rollback transaction
end
else
begin
print'更新成功,提交事务,写入硬盘永久保存'
commit transaction
end
go
运行的结果如下:
5
消息 8152,级别 16,状态 14,第 9 行
将截断字符串或二进制数据。
语句已终止。
SID Sname SmasterID Sprofile SclickCount StopicCount
----------- -------------------------------- ----------- -------------------------------------------------- ----------- -----------
2 .NET技术 5 讨论web/xml、net remoting、duwaming 800 7
sky发布的帖子新是:
板块 主题 帖子内容 发帖时间
----------- -------------------- -------------------------------------------------- -----------------------
更新成功,提交事务,写入硬盘永久保存
问题是:
1,消息 8152,级别 16,状态 14,第 9 行
将截断字符串或二进制数据。是怎么回事?
2、这是事务处理过程,如果插入数据库失败,应该执行回滚操作,但是却执行的是提交事务的结果,那里错了?小弟求高手予以解答,谢谢
--开始事务
begin transaction
declare @errorsum int ,@usersid int,@sectionid int,@topiccounts int
select @sectionid=sid from bbssection where sname='.NET技术'
set @errorsum =@errorsum+@@error
select @usersid=uid from bbsusers where uname='sky'
print @usersid
set @errorsum =@errorsum+@@error
insert into bbstopic (tsid,tuid,ttopic,tcontents)
values (@sectionid,@usersid,'小弟请问.NET配置问题','.NET配置具体需要那些环境啊,我的页面怎么跑不起来呢?')
set @errorsum =@errorsum+@@error
update bbssection set stopiccount=stopiccount+1 where sid= @sectionid
set @errorsum =@errorsum+@@error
select * from bbssection where sname='.NET技术'
set @errorsum =@errorsum+@@error
set @topiccounts=@@rowcount
if @topiccounts=1
begin
update bbsusers set upoint=upoint+100 where uid=@usersid
end
else
begin
update bbsusers set upoint=upoint+50 where uid=@usersid
end
update bbsusers
set uclass=case
when upoint <500 then 1
when upoint between 500 and 1000 then 2
when upoint between 1001 and 2000 then 3
when upoint between 2001 and 4000 then 4
when upoint between 4001 and 5000 then 5
else 6
end
set @errorsum =@errorsum+@@error
print 'sky发布的帖子新是:'
select 板块=tsid,主题=ttopic,帖子内容=tcontents,发帖时间=ttime from bbstopic where tuid=@usersid
set @errorsum =@errorsum+@@error
if @errorsum <>0
begin
print '更新失败,回滚事务'
rollback transaction
end
else
begin
print'更新成功,提交事务,写入硬盘永久保存'
commit transaction
end
go
运行的结果如下:
5
消息 8152,级别 16,状态 14,第 9 行
将截断字符串或二进制数据。
语句已终止。
SID Sname SmasterID Sprofile SclickCount StopicCount
----------- -------------------------------- ----------- -------------------------------------------------- ----------- -----------
2 .NET技术 5 讨论web/xml、net remoting、duwaming 800 7
sky发布的帖子新是:
板块 主题 帖子内容 发帖时间
----------- -------------------- -------------------------------------------------- -----------------------
更新成功,提交事务,写入硬盘永久保存
问题是:
1,消息 8152,级别 16,状态 14,第 9 行
将截断字符串或二进制数据。是怎么回事?
2、这是事务处理过程,如果插入数据库失败,应该执行回滚操作,但是却执行的是提交事务的结果,那里错了?小弟求高手予以解答,谢谢
...全文
相关推荐
sql语句妙用,各种sql语句的详细用法与讲解
sql语句妙用,各种sql语句的详细用法与讲解 ,使得程序运行的更加流畅。主要针对一些高效sql语句的解释。
Oracle Sql语句转换成Mysql Sql语句
Oracle Sql语句转换成Mysql Sql语句java 源码,非常简单,只要给定源oracle sql语句地址,和生成目标文件地址运行即可。
解决mybatis执行SQL语句部分参数返回NULL问题
主要介绍了mybatis执行SQL语句部分参数返回NULL问题,需要的的朋友参考下吧
sql语句、动态SQL语句基本语法
sql语句、动态SQL语句基本语法,里面有很多很有用的sql语句。
SQL语句语法
SQL语句语法,合适需要入门的同学学习,很基础的内容,需要可以下载。


疑难问题
