--====建立Test数据库====
Create database Test
Go
Use Test
go
--====建立 [部门信息]表====
Create table [部门信息]
(
[部门编号] varchar(3) Primary key,
[部门名称] varchar(10) not null,
[员工人数] int
)
go
--====建立[员工信息]表====
Create table [员工信息]
(
[员工编号] varchar(4) Primary key,
[员工姓名] varchar(10) not null,
[性别] varchar(2) Default'男',
[出生年月] datetime ,
[入职时间] datetime,
[部门编号] varchar(3),
Constraint ck foreign key([部门编号]) references [部门信息]([部门编号])
)
go
问题:Transact-SQL 为“员工信息”表创建名称为 dEmployee 的触发器,对应操作为INSERT、DELETE和UPDATA。要求:每当某部门有新员工入职或离职时,自动统计该部门的员工人数,更新到“部门信息”表的“员工人数”字段中。
各位帮忙解决一下...谢谢..写出T-SQL语句..
加多一问:Transact-SQL 为“员工信息”表创建名为uEmployee触发器,对应操作为INSERT,实现当对“员工信息”表插入新的数据时,自动将“入职时间”为当前系统时间。
本人属于初学者级别,对触发器的了解真的很少,请各位帮帮忙了..今晚就要...
我试过用INSERT都记录不了系统时间....请各位尽快给我一个解决方案好吗?最好就运行成功的...分我可以再追加..
关于T-SQL触发器的问题...
答案:2 悬赏:30
解决时间 2021-03-17 18:52
- 提问者网友:纹身骑士
- 2021-03-17 04:51
最佳答案
- 二级知识专家网友:茫然不知崩溃
- 2021-03-17 05:59
go
create trigger dEmployee_insert
on 部门信息
for insert
as
begin
update 部门信息
set 员工人数=员工人数+1
end
go
create trigger dEmployee_delete
on 部门信息
for delete
as
begin
update 部门信息
set 员工人数=员工人数-1
end
go
全部回答
- 1楼网友:一身浪痞味
- 2021-03-17 06:37
create table tblstudent
(
stuid int not null,
stuname char(10) not null,
stupwd varchar(20),
primary key(stuid)
)
go
create table tblcourse
(
stuid int not null,
courseid int not null,
score decimal(4,1),
primary key(stuid,courseid)
)
go
create trigger tr_1
on tblcourse
for insert
as
begin
declare @stuid int
--inserted表是触发器用于暂存刚刚插入的这条数据所临时存放的表
select @stuid=stuid from inserted
if not exists(select * from tblstudent where stuid=@stuid)
insert into tblstudent(stuid,stuname) values(@stuid,'xg')
end
go
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯