Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this question is for sql cod that is already given as below -- Create the SysLog

ID: 3708233 • Letter: T

Question

this question is for sql cod that is already given as below

-- Create the SysLog table

DROP TABLE IF EXISTS SysLog ;

CREATE TABLE IF NOT EXISTS SysLog (
ID INT NOT NULL AUTO_INCREMENT,
TableName VARCHAR(255) NOT NULL COMMENT 'The table that is being logged',
Message VARCHAR(255) NOT NULL COMMENT 'The logging message',
Created DATETIME NOT NULL DEFAULT NOW(),
PRIMARY KEY (ID)  
)
ENGINE = InnoDB
COMMENT 'The system log table' ;
CREATE UNIQUE INDEX SysLog_UNIQUE ON SysLog (ID ASC) ;

the qustion as below

this question is unclear because if the first top of the question is already creating trigger so do we have to create another trigger ??

[15] For this step, write an after update trigger that creates a record in a new table named SysLog whenever a record in the student table is changed. Name the trigger Student After_Update. Use the CreateSysLog.sql file included with the assignment to create the new table. 4. In your trigger, create a log record with table of 'Student' and a message that looks something like this "Updated ID-X" where Xis the ID of the student record that's been updated. After you've created the trigger, create and run update statements on several different student records, then run this SQL: SELECT* FROM SysLog ORDER BY ID DESC ;

Explanation / Answer

Find the below details,

1.The query that appers in the first top of this question is to create SysLog table.

2. Attached here the mysql tigger which insert a record into Syslog table when there is a change in the name of student record.

CREATE TRIGGER student_after_update AFTER UPDATE ON Student
FOR EACH ROW
BEGIN
IF NEW.StudentName <> OLD.StudentName THEN
INSERT INTO SysLog(TableName, Message) VALUES("Student",concat("Updated ID=", CONVERT(New.StudentID, nchar)));
END IF;
END;

Please comments if its still not clear.