各位帮忙看下这个sql语句的问题

hairelove 2010-09-22 10:57:02
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、这是事务处理过程,如果插入数据库失败,应该执行回滚操作,但是却执行的是提交事务的结果,那里错了?小弟求高手予以解答,谢谢
...全文
120 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
hairelove 2010-09-22
  • 打赏
  • 举报
回复
还有第二问题是怎么回事?
hairelove 2010-09-22
  • 打赏
  • 举报
回复
将ttopic或者tcontents字段长度改为20和100,问题解决,谢谢各位的帮助
ai_li7758521 2010-09-22
  • 打赏
  • 举报
回复
insert into bbstopic (tsid,tuid,ttopic,tcontents)
values (@sectionid,@usersid,'小弟请问.NET配置问题','.NET配置具体需要那些环境啊,我的页面怎么跑不起来呢?')
问题应该在这里,表bbstopic中ttopic或者tcontents字段长度不够大。
hao1hao2hao3 2010-09-22
  • 打赏
  • 举报
回复
ttopic为varchar(20)
tcontents为varchar(50)


这两个最好改成nvarchar(20),nvarchar(50)

因为你输入的是汉字,还有就是把20和50改大点看看有没有问题。
hairelove 2010-09-22
  • 打赏
  • 举报
回复
tsid,tuid 均为int类型的,
ttopic为varchar(20)
tcontents为varchar(50)
应该不会有字段长度不够的问题呀
hao1hao2hao3 2010-09-22
  • 打赏
  • 举报
回复
应该是表bbstopic (tsid,tuid,ttopic,tcontents)
里面的某个字段的长度不够,修改该字段的长度为更大的值后再试试。
dawugui 2010-09-22
  • 打赏
  • 举报
回复
1,消息 8152,级别 16,状态 14,第 9 行
将截断字符串或二进制数据。是怎么回事?

定义的字符串其长度不够。
Rotel-刘志东 2010-09-22
  • 打赏
  • 举报
回复
是定义字符串的长度不够导致。
笔试(erp系统管理员)题目 求解 偶乃一应届毕业生,上星期在网上见到一不错的公司招oracle数据库管理,于是屁颠屁颠跑到那公司,骗过门卫和保安,咨询了搞卫生的阿姨后,见到了人力资源部主管,话都没说上两句,给偶一道题目(erp系统管理员),结果没几个会做的。其实我自己也挺想往erp方向发展,所以打算下个星期再去。 请各位大虾们帮帮忙忙,提点提点。(我在论坛上查了些,资料,还是有好多不会的。) 1。列出 erp供应商及erp产品的名称,版本? (erp供应商是不是:racle erp在咱国内的用户比如,华菱、湘钢、衡钢、承 钢、济钢等等。名称和版本呢?) 2。名词解释 erp,crm,hr,oa,srm,pdm (我只查到了erp,crm,hr的解释,其他的查不到) 3。用一句话说明 bom,采购计划,生产订单,销售订单,物料清单 (查不到 ) 4。写sql语句。 ‘存货档案’(表一): 存货编码(c),存货名称(c),存货规格(c),存货类别(c) ‘发货单’(表二):存货编码(c),数量(n),单价(n) 用sql写出 A:存货类别为'办公用品',发货金额在1000元以下的所有发货单 B: 按存货名称汇总发货单的发货金额 (此题会做一点点,但是写得不全,还得请大家指导) 5 写出erp系统对'销售发货单',‘销售普通发票’生成的会计分录 (完全摸不着头脑)

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧