From d499230b181c108df54ca35643f8e84139c8fb9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=B8=96=E6=B6=9B?= <2124876211@qq.com> Date: Tue, 11 Oct 2022 20:14:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9E=97=E4=B8=96=E6=B6=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2022.10.10\344\275\234\344\270\232.sql" | 24 +++++++++++++++++++ .../2022.10.10\347\254\224\350\256\260.md" | 10 ++++++++ 2 files changed, 34 insertions(+) create mode 100644 "23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.10.10\344\275\234\344\270\232.sql" create mode 100644 "23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.10.10\347\254\224\350\256\260.md" diff --git "a/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.10.10\344\275\234\344\270\232.sql" "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.10.10\344\275\234\344\270\232.sql" new file mode 100644 index 0000000..b04fa89 --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\344\275\234\344\270\232/2022.10.10\344\275\234\344\270\232.sql" @@ -0,0 +1,24 @@ +--假设有部门表和员工表,在添加员工的时候,该员工的部门编号如果在部门表中找不到,则自动添加部门信息,部门名称为"新部门"。 +create trigger huhu +on people for insert +as + insert into Department values ((select DepartmentId from inserted),'新部门') +go + +insert into People(DepartmentId,PeopleName,PeopleSex,PeopleSalary) values ('123','咕咕','男',200) +--触发器实现,删除一个部门的时候将部门下所有员工全部删除。 +create trigger huahua +on department for delete +as + delete from people where DepartmentId=(select DepartmentId from deleted) +go + +delete from Department where DepartmentId='123' +--修改一个部门编号之后,将该部门下所有员工的部门编号同步进行修改 +create trigger gugu +on department for update +as + update People set DepartmentId=(select DepartmentId from inserted) where DepartmentId=(select DepartmentId from deleted) +go + +update Department set DepartmentId='004' where DepartmentId='123' \ No newline at end of file diff --git "a/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.10.10\347\254\224\350\256\260.md" "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.10.10\347\254\224\350\256\260.md" new file mode 100644 index 0000000..ea7fe13 --- /dev/null +++ "b/23\346\236\227\344\270\226\346\266\233/\347\254\224\350\256\260/2022.10.10\347\254\224\350\256\260.md" @@ -0,0 +1,10 @@ +create tirgger 名 +on 表 for isnert/delete/update +as +********* + + + + +inserted(新数据) +deleted(旧数据) \ No newline at end of file -- Gitee