H
hurryman
Unregistered / Unconfirmed
GUEST, unregistred user!
这个触发器有什么问题?
好不容易才找到工作,放假都不能休息没办法呀,帮帮我吧
1,
假如我想在用户插入一条记录时,数据库自动将NAME改为
'职工'这两个字,我写了一个触发器,但没有效果呀
大家帮我看看,用游标也可以
2,假如我的A表里有一条M记录,当我想B表里添加一条N记录
的同时我想删除掉A表里的M着条记录,这个触发器咋写?
use worker
if exists (select name from sysobjects where name='adduser2' and type='p')
drop procedure adduser2
go
if exists (select name from sysobjects where name='del1' and type='p')
drop procedure del1
go
if exists (select * from sysobjects where id = object_id(N'[dbo].[us]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[us]
GO
CREATE TABLE [dbo].[us] (
[name] [varchar] (10) not null,
[sex] [char] (4) not null )
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
create PROCEDURE adduser2
(@name varchar(10) ,
@sex char(4),
@retmsg varchar(20) output
)
AS
if @name in (select name from us where name=@name)
begin
select retmsg='该职工以存在了'
return 0
end
begin tran
insert into us (name,sex) values (@name ,@sex)
commit tran
select @retmsg='该职工资料添加成功'
GO
select * from us
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
create trigger del1 on us
for update
as
update us set name='职工'
GO
select * from us
GO
好不容易才找到工作,放假都不能休息没办法呀,帮帮我吧
1,
假如我想在用户插入一条记录时,数据库自动将NAME改为
'职工'这两个字,我写了一个触发器,但没有效果呀
大家帮我看看,用游标也可以
2,假如我的A表里有一条M记录,当我想B表里添加一条N记录
的同时我想删除掉A表里的M着条记录,这个触发器咋写?
use worker
if exists (select name from sysobjects where name='adduser2' and type='p')
drop procedure adduser2
go
if exists (select name from sysobjects where name='del1' and type='p')
drop procedure del1
go
if exists (select * from sysobjects where id = object_id(N'[dbo].[us]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[us]
GO
CREATE TABLE [dbo].[us] (
[name] [varchar] (10) not null,
[sex] [char] (4) not null )
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
create PROCEDURE adduser2
(@name varchar(10) ,
@sex char(4),
@retmsg varchar(20) output
)
AS
if @name in (select name from us where name=@name)
begin
select retmsg='该职工以存在了'
return 0
end
begin tran
insert into us (name,sex) values (@name ,@sex)
commit tran
select @retmsg='该职工资料添加成功'
GO
select * from us
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
create trigger del1 on us
for update
as
update us set name='职工'
GO
select * from us
GO