add solutions for the trigger excercise
This commit is contained in:
parent
fa29cac4d4
commit
035e48110c
|
@ -37,6 +37,12 @@
|
||||||
<AssociatedConnUserName />
|
<AssociatedConnUserName />
|
||||||
<FullPath>insert_data.sql</FullPath>
|
<FullPath>insert_data.sql</FullPath>
|
||||||
</FileNode>
|
</FileNode>
|
||||||
|
<FileNode Name="triggger_solutions.sql">
|
||||||
|
<AssociatedConnectionMoniker>8c91a03d-f9b4-46c0-a305-b5dcc79ff907:(local)\SQLEXPRESS:True</AssociatedConnectionMoniker>
|
||||||
|
<AssociatedConnSrvName>(local)\SQLEXPRESS</AssociatedConnSrvName>
|
||||||
|
<AssociatedConnUserName />
|
||||||
|
<FullPath>triggger_solutions.sql</FullPath>
|
||||||
|
</FileNode>
|
||||||
</Items>
|
</Items>
|
||||||
</LogicalFolder>
|
</LogicalFolder>
|
||||||
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
|
<LogicalFolder Name="Miscellaneous" Type="3" Sorted="true">
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
-- Daten einfügen
|
-- Daten einfügen
|
||||||
|
use BuchAutorDB;
|
||||||
INSERT INTO buch.tblBuch
|
INSERT INTO buch.tblBuch
|
||||||
VALUES ('3-89842-141-1', 'SELECT * FROM SQL Server 2000', 49.90);
|
VALUES ('3-89842-141-1', 'SELECT * FROM SQL Server 2000', 49.90);
|
||||||
INSERT INTO buch.tblBuch (ISBN, Titel)
|
INSERT INTO buch.tblBuch (ISBN, Titel)
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
-- ================================================
|
||||||
|
-- Template generated from Template Explorer using:
|
||||||
|
-- Create Trigger (New Menu).SQL
|
||||||
|
--
|
||||||
|
-- Use the Specify Values for Template Parameters
|
||||||
|
-- command (Ctrl-Shift-M) to fill in the parameter
|
||||||
|
-- values below.
|
||||||
|
--
|
||||||
|
-- See additional Create Trigger templates for more
|
||||||
|
-- examples of different Trigger statements.
|
||||||
|
--
|
||||||
|
-- This block of comments will not be included in
|
||||||
|
-- the definition of the function.
|
||||||
|
-- ================================================
|
||||||
|
SET ANSI_NULLS ON
|
||||||
|
GO
|
||||||
|
SET QUOTED_IDENTIFIER ON
|
||||||
|
GO
|
||||||
|
-- =============================================
|
||||||
|
-- Author: Zweili Andreas
|
||||||
|
-- Create date: 2017-11-24
|
||||||
|
-- Description:
|
||||||
|
-- =============================================
|
||||||
|
ALTER TRIGGER buch.trigAutorBuch_Insert_Update
|
||||||
|
ON buch.tblAutorBuch
|
||||||
|
AFTER INSERT, UPDATE
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
-- SET NOCOUNT ON added to prevent extra result sets from
|
||||||
|
-- interfering with SELECT statements.
|
||||||
|
SET NOCOUNT ON;
|
||||||
|
|
||||||
|
-- Insert statements for trigger here
|
||||||
|
|
||||||
|
declare @ID int;
|
||||||
|
declare @ISBN char(13);
|
||||||
|
declare @anteil decimal(5,2);
|
||||||
|
declare @anteil_summe decimal(5,2);
|
||||||
|
|
||||||
|
select @ID = ID, @ISBN = ISBN from inserted;
|
||||||
|
|
||||||
|
select @anteil_summe = sum(Anteil) from tblAutorBuch
|
||||||
|
where tblAutorBuch.ISBN = @ISBN;
|
||||||
|
|
||||||
|
if @anteil_summe > 100.00 delete from tblAutorBuch
|
||||||
|
where tblAutorBuch.ID = @ID;
|
||||||
|
print 'Summe ist zu hoch'
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- Trigger Test
|
||||||
|
use BuchAutorDB;
|
||||||
|
insert into buch.tblAutor (Nachname, Vorname)
|
||||||
|
values ('Muster', 'Max');
|
||||||
|
|
||||||
|
insert into buch.tblAutorBuch (ID, ISBN, Anteil)
|
||||||
|
values (1, '3-89842-129-5', 90.00);
|
||||||
|
|
||||||
|
insert into buch.tblAutorBuch (ID, ISBN, Anteil)
|
||||||
|
values (2, '3-89842-129-5', 15.00);
|
Reference in New Issue