You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Automatyczne dodawanie studenta do webinaru po jego zakupieniu
CREATE TRIGGER [dbo].[trg_AddStudentToWebinar]
ON [dbo].[OrderWebinars]
AFTER INSERT
ASBEGIN
IF EXISTS (
SELECT StudentID
FROM inserted
INNER JOIN OrderDetails
ONinserted.OrderDetailsID=OrderDetails.OrderDetailsIDINNER JOIN Orders
ONOrderDetails.OrderID=Orders.OrderIDWHERE StudentID IN (
SELECT DISTINCT StudentID
FROM inserted
INNER JOIN WebinarDetails
ONinserted.WebinarID=WebinarDetails.WebinarID
)
)
BEGIN
RAISERROR('Student o podanym ID jest już zapisany na ten webinar.', 16, 1);
END
ELSE
BEGININSERT INTO WebinarDetails (StudentID, WebinarID, AvailableDue)
SELECTOrders.StudentID, inserted.WebinarID, DATEADD(DAY, 30, GETDATE())
FROM inserted
INNER JOIN OrderDetails
ONinserted.OrderDetailsID=OrderDetails.OrderDetailsIDINNER JOIN Orders
ONOrderDetails.OrderID=Orders.OrderID;
END
END;
Automatyczne dodawanie studenta do kursów i modułów kursu po jego zakupieniu
CREATE TRIGGER [dbo].[trg_AddStudentToCourse]
ON [dbo].[OrderCourse]
AFTER INSERT
ASBEGIN
IF EXISTS (
SELECT StudentID
FROM inserted
INNER JOIN OrderDetails
ONinserted.OrderDetailsID=OrderDetails.OrderDetailsIDINNER JOIN Orders
ONOrderDetails.OrderID=Orders.OrderIDWHERE StudentID IN (
SELECT DISTINCT StudentID
FROM inserted
INNER JOIN CourseDetails
ONinserted.CourseID=CourseDetails.CourseID
)
)
BEGIN
RAISERROR('Student o podanym ID jest już zapisany na ten kurs.', 16, 1);
END
ELSE
BEGIN
DECLARE @StudentID int;
SELECT @StudentID =Orders.StudentIDFROM inserted
INNER JOIN OrderDetails
ONinserted.OrderDetailsID=OrderDetails.OrderDetailsIDINNER JOIN Orders
ONOrderDetails.OrderID=Orders.OrderID;
INSERT INTO CourseDetails (CourseID, StudentID)
SELECTinserted.CourseID, @StudentID
FROM inserted;
INSERT INTO CourseModulesDetails (ModuleID, StudentID, Presence)
SELECTCourseModules.ModuleID, @StudentID, 0FROM inserted
INNER JOIN CourseModules
ONinserted.CourseID=CourseModules.CourseID;
END
END
Automatyczne dodawanie studenta do spotkania studyjnego po jego zakupieniu
CREATE TRIGGER [dbo].[trg_AddStudentToStudyMeeting]
ON [dbo].[OrderStudyMeeting]
AFTER INSERT
ASBEGIN
IF EXISTS (
SELECT StudentID
FROM inserted
INNER JOIN OrderDetails
ONinserted.OrderDetailsID=OrderDetails.OrderDetailsIDINNER JOIN Orders
ONOrderDetails.OrderID=Orders.OrderIDWHERE StudentID IN (
SELECT DISTINCT StudentID
FROM inserted
INNER JOIN StudyMeetingDetails
ONinserted.StudyMeetingID=StudyMeetingDetails.StudyMeetingID
)
)
BEGIN
RAISERROR('Student o podanym ID jest już zapisany na to spotkanie studyjne.', 16, 1);
END
ELSE
BEGININSERT INTO StudyMeetingDetails (StudyMeetingID, StudentID, Presence)
SELECTinserted.StudyMeetingID, Orders.StudentID, 0FROM inserted
INNER JOIN OrderDetails
ONinserted.OrderDetailsID=OrderDetails.OrderDetailsIDINNER JOIN Orders
ONOrderDetails.OrderID=Orders.OrderID;
END
END;
Automatyczne dodawanie studenta do studiów i odpowiednich spotkań studyjnych po jego zakupieniu
CREATE TRIGGER [dbo].[trg_AddStudentToStudy]
ON [dbo].[OrderStudies]
AFTER INSERT
ASBEGIN
IF EXISTS (
SELECT StudentID
FROM inserted
INNER JOIN OrderDetails
ONinserted.OrderDetailsID=OrderDetails.OrderDetailsIDINNER JOIN Orders
ONOrderDetails.OrderID=Orders.OrderIDWHERE StudentID IN (
SELECT DISTINCT StudentID
FROM inserted
INNER JOIN StudiesDetails
ONinserted.StudiesID=StudiesDetails.StudiesID
)
)
BEGIN
RAISERROR('Student o podanym ID jest już zapisany na te studia.', 16, 1);
END
ELSE IF EXISTS (
SELECT StudentID
FROM inserted
INNER JOIN OrderDetails
ONinserted.OrderDetailsID=OrderDetails.OrderDetailsIDINNER JOIN Orders
ONOrderDetails.OrderID=Orders.OrderIDWHEREdbo.IsStudentInAnyStudyMeeting(StudentID, inserted.StudiesID) =1
)
BEGIN
RAISERROR('Student o podanym ID jest zapisany na jedno ze spotkań tych studiów.', 16, 1);
END
ELSE
BEGIN
DECLARE @StudentID int;
SELECT @StudentID =Orders.StudentIDFROM inserted
INNER JOIN OrderDetails
ONinserted.OrderDetailsID=OrderDetails.OrderDetailsIDINNER JOIN Orders
ONOrderDetails.OrderID=Orders.OrderID;
INSERT INTO StudiesDetails (StudiesID, StudentID, StudiesGrade)
SELECTinserted.StudiesID, @StudentID, 2FROM inserted;
INSERT INTO StudyMeetingDetails (StudyMeetingID, StudentID, Presence)
SELECTStudyMeeting.StudyMeetingID, @StudentID, 0FROM inserted
INNER JOIN Subject
ONinserted.StudiesID=Subject.StudiesIDINNER JOIN StudyMeeting
ONSubject.SubjectID=StudyMeeting.SubjectID;
END
END;