Зертханалық 14
Айтбай Рахымжан
DELIMITER |
CREATE TRIGGER test_student BEFORE INSERT ON Decanat
FOR EACH ROW
BEGIN
SET NEW.Name = LEFT(NEW.Name, 1);
SET NEW.Otchestvo = LEFT(NEW.Otchestvo, 1);
END;
|
INSERT INTO Decanat (IdCodstudent, Familia, Name, Otchestvo, Datarozhdenia, Gruppa, Codspecialnost)
VALUES (7, 'Бурдыбек', 'Семсер', 'Арманұлы', '07.08.2005', 'ИС 22-11', 1);
select * from Decanat
Пример 2. Создание триггера BEFORE UPDATE
DELIMITER |
CREATE TRIGGER test_student2 BEFORE UPDATE ON Decanat
FOR EACH ROW
BEGIN
SET NEW.Name = LEFT(NEW.Name, 1);
SET NEW.Otchestvo = LEFT(NEW.Otchestvo, 1);
END;
|
UPDATE Decanat SET
Familia = 'Исаева',
Name = 'Д',
Otchestvo = 'Д',
Gruppa = 'ИС-23-12',
Datarozhdenia = '2004-12-07'
WHERE IdCodstudent = 6;
select * from Decanat
Пример 3. Создание триггера BEFORE DELETE
DELIMITER |
CREATE TRIGGER test_student3 BEFORE DELETE ON Decanat
FOR EACH ROW
BEGIN
INSERT INTO student_clone (IdCodstudent, Familia, Name, Otchestvo, Gruppa, Datarozhdenia)
VALUES (OLD.IdCodstudent, OLD.Familia, OLD.Name, OLD.Otchestvo, OLD.Gruppa, OLD.Datarozhdenia);
END;
|
DELETE FROM Decanat
WHERE IdCodstudent = 1;
Измените структуру таблицы Decanat, добавьте в неё поле Stip_New (новая стипендия).
ALTER TABLE Decanat
ADD COLUMN Stip_New DECIMAL(10, 2);
select * from decanat
Достарыңызбен бөлісу: |