• SQL 触发器


    创建表tbl_student,tbl_luofx

    CREATE TABLE [dbo].[tbl_luofx](
    [t_name] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NOT NULL,
    [id] [int] NULL
    ) ON [PRIMARY]
    CREATE TABLE [dbo].[tbl_Student](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [学生ID] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
    [学生姓名] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
    [课程ID] [nchar](10) COLLATE Chinese_PRC_CI_AS NULL,
    [课程名称] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
    [成绩] [int] NULL,
    [教师ID] [varchar](50) COLLATE Chinese_PRC_CI_AS NULL,
    [教师姓名] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL
    ) ON [PRIMARY]

    创建触发器[Tri_tbl_Student_I]、[Tri_tbl_Student_D]

    CREATE TRIGGER [dbo].[Tri_tbl_Student_I]
    ON [dbo].[tbl_Student] FOR INSERT
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
    declare @id int;
    select @id=id from inserted
    INSERT INTO tbl_luofx values('测试触发器',@id)
    -- Insert statements for trigger here
    SET NOCOUNT off;
    END
    CREATE TRIGGER [dbo].[Tri_tbl_Student_D]
    ON [dbo].[tbl_Student] FOR DELETE
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for trigger here
    DELETE FROM tbl_luofx where id in(select id from deleted)
    SET NOCOUNT OFF;
    END
  • 相关阅读:
    Docker02 Docker初识:第一个Docker容器和Docker镜像
    Docker01 CentOS配置Docker
    Jenkins02:Jenkins+maven+svn集成
    Junit01 新建Maven项目
    Junit02 Junit创建及简单实现
    Jenkins01:linux+jenkins+ant+jmeter集成
    Jenkins初识03:构建定时任务
    python 协程
    python之socket 网络编程
    python 面向对象
  • 原文地址:https://www.cnblogs.com/luofuxian/p/2364568.html
Copyright © 2020-2023  润新知