| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 784 人关注过本帖
标题:[求助]无法向表中添加数据(触发器)
只看楼主 加入收藏
非凡DZ
Rank: 1
等 级:新手上路
帖 子:231
专家分:0
注 册:2007-4-6
收藏
 问题点数:0 回复次数:5 
[求助]无法向表中添加数据(触发器)

use stuDB
go
if exists(select * from sysobjects where name='bank')
drop table bank
if exists(select * from sysobjects where name='transInfo')
drop table transInfo
go
create table bank
(
customerName nvarchar(10) not null,
cardID char(8) not null,
currentMoney money not null
)
go
create table transInfo
(
cardID char(8) not null,
transType nvarchar(4) not null,
transMoney money not null,
transDate datetime not null
)
go
alter table bank
add constraint CK_currentMoney check(currentMoney>=1)
alter table transInfo
add constraint DF_transDate default(getdate()) for transDate
go
insert into bank values('张三','10010001',1000)
insert into bank values('李四','10010002',1)

use stuDB
go
if exists(select * from sysobjects where name='trig_transInfo1')
drop trigger trig_transInfo1
go
create trigger trig_transInfo1
on bank
for insert
as
declare @tempCardID char(8),@tempMoney money
select @tempCardID=cardID,@tempMoney=currentMoney from inserted
if(@tempMoney>=50000)
begin
print '交易金额:'+convert(varchar(8),@tempMoney)
print '贵宾客户'
end
else
begin
print '交易金额:'+convert(varchar(8),@tempMoney)
print '普通客户'
end
insert into transInfo values('@tempCardID','存入',@tempMoney,default)--是不是这句话写得有问题呢
go

insert into bank values('王五','10010003',200)--为什么不能向bank中添加数据呢
select * from bank
select * from transInfo


错误提示
交易金额:200.00
普通客户
服务器: 消息 8152,级别 16,状态 9,过程 trig_transInfo1,行 17
将截断字符串或二进制数据。
语句已终止。
请问是哪里出了问题 请高手指点

[此贴子已经被作者于2007-10-9 16:39:50编辑过]

搜索更多相关主题的帖子: 触发器 null not table 数据 
2007-10-09 14:47
西风独自凉
Rank: 8Rank: 8
等 级:贵宾
威 望:43
帖 子:3380
专家分:28
注 册:2007-8-2
收藏
得分:0 
數據庫中字段長度設定太小。。。

2007-10-09 15:27
非凡DZ
Rank: 1
等 级:新手上路
帖 子:231
专家分:0
注 册:2007-4-6
收藏
得分:0 
能说具体一些吗
具体是哪个字段不够长
还有我之前的数据和我现在要插入的数据是一样长的 问题应该不在这里

2007-10-09 15:38
西风独自凉
Rank: 8Rank: 8
等 级:贵宾
威 望:43
帖 子:3380
专家分:28
注 册:2007-8-2
收藏
得分:0 

自己仔細檢查一下。


2007-10-09 15:50
非凡DZ
Rank: 1
等 级:新手上路
帖 子:231
专家分:0
注 册:2007-4-6
收藏
得分:0 
insert into transInfo values('@tempCardID','存入',@tempMoney,default)--是不是这句话写得有问题呢
拷贝的时候丢了个'号
不过我的源程序中是有的
版主能不能指点下
我实在是找不着了

2007-10-09 16:41
非凡DZ
Rank: 1
等 级:新手上路
帖 子:231
专家分:0
注 册:2007-4-6
收藏
得分:0 
问题解决了
insert into transInfo values(@tempCardID,'存入',@tempMoney,default)
变量放在''中 就不能称为变量了

2007-10-09 17:02
快速回复:[求助]无法向表中添加数据(触发器)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015587 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved