无法向表中添加数据(触发器)

来源:百度知道 编辑:UC知道 时间:2024/07/02 06:32:22
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<

你贴出的代码绝对有问题,就在你注释的那一行。

不管怎样,变量外边加上单引号就不是变量了。

insert into transInfo values(@tempCardID,'存入',@tempMoney,default)

insert into transInfo values('@tempCardID',存入',@tempMoney,default)
这地方确实少了分号,你仔细看看。应该
insert into transInfo values('@tempCardID','存入',@tempMoney,default)

insert into bank values('王五','10010003',200)--为什么不能向bank中添加数据呢
这个没什么问题,引起问题的应该在前边