The document describes creating triggers on tables "Mahasiswa" and "Dosen" that log insert, update, and delete actions to the "TABLE_LOG" table. Triggers are created for each action on each table that declare variables from the inserted/deleted tables, get the current date, and insert a record into TABLE_LOG with the action type, date, and table name. Examples are provided for each trigger to demonstrate functionality.
The document describes creating triggers on tables "Mahasiswa" and "Dosen" that log insert, update, and delete actions to the "TABLE_LOG" table. Triggers are created for each action on each table that declare variables from the inserted/deleted tables, get the current date, and insert a record into TABLE_LOG with the action type, date, and table name. Examples are provided for each trigger to demonstrate functionality.
The document describes creating triggers on tables "Mahasiswa" and "Dosen" that log insert, update, and delete actions to the "TABLE_LOG" table. Triggers are created for each action on each table that declare variables from the inserted/deleted tables, get the current date, and insert a record into TABLE_LOG with the action type, date, and table name. Examples are provided for each trigger to demonstrate functionality.
--Insert Trigger Mahasiswa CREATE TRIGGER Tr_Changetype_Insert_Mahasiswa ON Mahasiswa FOR INSERT AS BEGIN SET NOCOUNT ON
DECLARE @NIM AS char(9)
DECLARE @Nama AS varchar(50) DECLARE @Alamat AS varchar(50) DECLARE @Jurusan AS char(3) DECLARE @Semester AS Int DECLARE @Date datetime DECLARE @NamaTabel varchar(255) = 'Mahasiswa'
SET @Date = GETDATE()
SELECT @NIM = NIM, @Nama = Nama, @Alamat = Alamat, @Jurusan = Jurusan, @Semester = Semester FROM inserted INSERT INTO TABLE_LOG VALUES('Insert', @Date, @NamaTabel) END
CREATE TRIGGER Tr_Changetype_Delete_Mahasiswa ON Mahasiswa FOR DELETE AS BEGIN SET NOCOUNT ON
DECLARE @NIM AS char(9)
DECLARE @Nama AS varchar(50) DECLARE @Alamat AS varchar(255) DECLARE @Jurusan AS char(3) DECLARE @Semester AS Int DECLARE @Date datetime DECLARE @NamaTabel varchar(255) = 'Mahasiswa'
SET @Date = GETDATE()
SELECT @NIM = NIM, @Nama = Nama, @Alamat = Alamat, @Jurusan = Jurusan, @Semester = Semester FROM deleted INSERT INTO TABLE_LOG VALUES ('Delete', @Date, @NamaTabel) END
DELETE FROM Mahasiswa
WHERE NIM = 180210326 --Update Trigger Mahasiswa CREATE TRIGGER Tr_Changetype_Update_Mahasiswa ON Mahasiswa FOR UPDATE AS BEGIN SET NOCOUNT ON
DECLARE @NIM AS char(9)
DECLARE @Nama AS varchar(50) DECLARE @Alamat AS varchar(255) DECLARE @Jurusan AS char(3) DECLARE @Semester AS Int DECLARE @Date datetime DECLARE @NamaTabel varchar (255) = 'Mahasiswa'
SET @Date = GETDATE()
SELECT @NIM = NIM, @Nama = Nama, @Alamat = Alamat, @jurusan = Jurusan, @Semester = Semester FROM inserted INSERT INTO TABLE_LOG VALUES ('Update', @Date, @NamaTabel) END
DROP TRIGGER Tr_Changetype_Update_Mahasiswa
UPDATE Mahasiswa SET Nama = Lovelin', Alamat = 'Simalingkar A' WHERE NIM = 160210345
--Insert Trigger Dosen
CREATE TRIGGER Tr_Changetype_Insert_Dosen ON Dosen FOR INSERT AS BEGIN SET NOCOUNT ON