0% found this document useful (0 votes)
2 views2 pages

Assignment 10

The document outlines the creation of a MySQL database named 'assignment_10' with two tables: 'Members' and 'reminders'. A trigger named 'reminder_after_insert' is established to automatically insert a reminder message into the 'reminders' table if a new member's birth date is not provided. The document also includes sample data insertion and retrieval from both tables, demonstrating the trigger's functionality.

Uploaded by

Mrinmoy Pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Assignment 10

The document outlines the creation of a MySQL database named 'assignment_10' with two tables: 'Members' and 'reminders'. A trigger named 'reminder_after_insert' is established to automatically insert a reminder message into the 'reminders' table if a new member's birth date is not provided. The document also includes sample data insertion and retrieval from both tables, demonstrating the trigger's functionality.

Uploaded by

Mrinmoy Pathak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

mysql> use assignment_10;

Database changed

mysql> CREATE TABLE Members (


-> id INT PRIMARY KEY,
-> name VARCHAR(50),
-> email VARCHAR(100),
-> birthDate DATE
-> );
Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE reminders (


-> id INT AUTO_INCREMENT PRIMARY KEY,
-> member_id INT,
-> message VARCHAR(255)
-> );
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER $$
mysql> CREATE TRIGGER reminder_after_insert
-> AFTER INSERT ON Members
-> FOR EACH ROW
-> BEGIN
-> IF NEW.birthDate IS NULL THEN
-> INSERT INTO reminders (member_id, message)
-> VALUES (NEW.id, 'Please fill in your date of birth.');
-> END IF;
-> END;
-> $$
Query OK, 0 rows affected (0.00 sec)

mysql> DELIMITER ;

mysql> INSERT INTO Members (id, name, email, birthDate) VALUES (1, 'John Doe',
'[email protected]', '1990-01-15');
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO Members (id, name, email) VALUES (2, 'Jane Smith',
'[email protected]');
Query OK, 1 row affected (0.00 sec)

mysql> select * from Members;


+----+------------+------------------+------------+
| id | name | email | birthDate |
+----+------------+------------------+------------+
| 1 | John Doe | [email protected] | 1990-01-15 |
| 2 | Jane Smith | [email protected] | NULL |
+----+------------+------------------+------------+
2 rows in set (0.00 sec)

mysql> select * from reminders;


+----+-----------+------------------------------------+
| id | member_id | message |
+----+-----------+------------------------------------+
| 1 | 2 | Please fill in your date of birth. |
+----+-----------+------------------------------------+
1 row in set (0.00 sec)

You might also like