--添加
create trigger InStudent
on Student
for insert
as
declare @id int
declare @name varchar(50)
select @id=id,@name=name from inserted
begin
insert dbo.BorrowRecord(sid,sname) values(@id,@name)
end
go
---修改
create trigger upStudent
on Student
for update
as
if update([name])
begin
update BorrowRecord set sname=i.[name] from BorrowRecord br, deleted d,inserted i
where br.id=d.id
end
【简单的触发器例题】--删除s
create trigger deStudent
on Student
for Delete
as
delete BorrowRecord from BorrowRecord br, deleted d
where br.sid=d.id
推荐阅读
- 数据库|SQL行转列方式优化查询性能实践
- SqlServer|sql server的UPDLOCK、HOLDLOCK试验
- SQL|SQL基本功(五)--函数、谓词、CASE表达式
- SQL|SQL基本功(三)-- 聚合与排序
- web挖洞|HACK学习黑帽子Python--漏洞检测脚本快速编写
- sqlite|python中用SQLite3添加 主键约束 唯一约束 非空约束 外键约束(约束的介绍以及设置)
- python|python中使用SQLite3对数据库的基本操作(基于ubuntu操作系统)
- TDSQL | DTS for PostgreSQL 逻辑复制详解
- TDSQL | 《checkpoint 原理浅析》
- TDSQL-A 技术架构演进及创新实践