Question

In: Computer Science

Write an AFTER Insert trigger for the following Employee table. Check Date of Birth and calculate...

Write an AFTER Insert trigger for the following Employee table. Check Date of Birth and calculate age. Update AGE field with calculated value in Employee_Info table

  • Employee (Emp_ID int, DOB date)

  • Employee_Info (Emp_ID int, Fname char, Lname char, Age int)

  • Set variable Current_Date to CURDATE()

  • Substract DOB from Current_Date to find Age

Solutions

Expert Solution

Trigger is a object of the mysql database which will automatically execute once user will perform operation like insert, update, delete.

Steps to create trigger as per question:

1. We will create two variable to store current date and age

2. Then we will update the Employee_Info table by using WHERE clause.

3. For getting current date we will use CURDATE() pre-defined function to get the current date.

4. For getting the age we will use, DATE_FORMAT(), FROM_DAYS(), and DATEDIFF() functions.

----------------------------------------------------------------------------------------

CREATE TRIGGER after_dob_insert

AFTER INSERT

ON Employee FOR EACH ROW

BEGIN

DECLARE Current_date date;

DECLARE User_age int;

Current_date = Select CURDATE();

User_age = Select DATE_FORMAT(FROM_DAYS(DATEDIFF(Current_date,new.DOB)),'%Y')+0;

UPDATE Employee_Info SET Age = User_age WHERE Emp_ID = new.Emp_ID;

END //

-----------------------------------------------------------------------------------------------


Related Solutions

Mina, age 50, has a business with the following employees: Employee Date of Birth Employment Start...
Mina, age 50, has a business with the following employees: Employee Date of Birth Employment Start Date Compensation Ali 4/24/1985 6/30/2017 $56,000 Bob 6/25/1976 2/30/2010 $120,000 Cindy 3/15/1987 4/25/2008 $75,000 David 2/4/1997 7/14/17 $87,000 Edward 2/28/1993 10/14/2012 $47,000 Mina earns $450,000 and has for about 4 years. There is no retirement plan now and Mina would like to adopt one that will give her personally the most beneficial and cost the minimum amount for her employees. What plans should Mina...
Write a program to insert the following elements into a hash table of size 17. The...
Write a program to insert the following elements into a hash table of size 17. The hash function is X mod 17 where X is the input element.   6, 12, 34, 29, 28, 11, 23, 7, 0, 33, 30, 45 Use linear probing to resolve any collisions.
Create a table ‘StudentInfo’ with following fields: ID First Name Last Name SSN Date of Birth...
Create a table ‘StudentInfo’ with following fields: ID First Name Last Name SSN Date of Birth Create a table ‘ClassInfo’ table: ID Class Name Class Description Create a table ‘RegisteredClasses’ table: StudentID ClassID The RegisteredClasses table should have a foreign key relationship to StudentInfo and ClassInfo tables for the respective IDs. Also the IDs in StudentInfo and ClassInfo need to be primary keys. When you submit the file your email should also contain the following SQL Queries: Query to show...
What is wrong with the following INSERT commands: INSERT IN EMPLOYEE (EmployeeNumber, FirstName, LastName, Department, Position,...
What is wrong with the following INSERT commands: INSERT IN EMPLOYEE (EmployeeNumber, FirstName, LastName, Department, Position, Supervisor, OfficePhone, EmailAddress) VALUES (5,'Alan','Adams','Human','H R 1',4,'360-285-8320','[email protected]'); INSERT INTO (EmployeeNumber, FirstName, LastName, Department, Position, Supervisor, OfficePhone, EmailAddress) VALUES (5,'Alan','Adams','Human','H R 1',4,'360-2858320','[email protected]'); INSERT INTO EMPLOYEE (EmployeeNumber, FirstName, LastName, Department, Position, Supervisor, OfficePhone, EmailAddress) VALUES ('Alan','Adams','Human','H R 1',4,'360285-8320','[email protected]'); INSERT INTO EMPLOYEE (EmployeeNumber, FirstName, LastName, Department, Position, Supervisor, OfficePhone, EmailAddress) VALUES ('Alan','Adams','Human','H R 1',4,'360285-8320','[email protected]')
Write a program that prompts the user to enter a person’s date of birth in numeric...
Write a program that prompts the user to enter a person’s date of birth in numeric form such as 8-27-1980. The program then outputs the date of birth in the form: August 27, 1980. Your program must contain at least two exception classes: invalidDay and invalidMonth. If the user enters an invalid value for day, then the program should throw and catch an invalidDay object. Follow similar conventions for the invalid values of month and year. (Note that your program...
Write a Java program that will add the digits of a person’s birth date to obtain...
Write a Java program that will add the digits of a person’s birth date to obtain a single digit to generate a numerology number. Write one separate method for each of the following tasks (it goes w/o saying that you will have a main() method along with these): date validating date crunching First: Get a Date Numerology has been used since ancient times to shed light on relationships, health, and global events. Each element in a birth date is believed...
Write a trigger to record any insertion changes in the stock table. Be sure to create...
Write a trigger to record any insertion changes in the stock table. Be sure to create a table to record any changes. Submit all your SQL code as well a screenshot of the new table showing any new insertion entries.
List the name, type, breed and date of birth for all cats or dogs born after...
List the name, type, breed and date of birth for all cats or dogs born after January 1, 2000. The data should be sorted by date of birth (ascending). I have a database with a few tables. And while creating a query, this is one of my questions. I do not know how to filter my data in this table by the date MS ACCESS
In this exercise, you’ll write a program that accepts a person’s birth date from the console...
In this exercise, you’ll write a program that accepts a person’s birth date from the console and displays the person’s age in years. To make that easier to do, we’ll give you a class that contains the code for accepting the birth date. The console output for the program should look something like this: f Welcome to the age calculator. j Enter the month you were born (1 to 12) : 5 Enter the day of the month you were...
Write a PowerShell script that will ask your name, Date of Birth (DOB). Print a message...
Write a PowerShell script that will ask your name, Date of Birth (DOB). Print a message on console with a message like the examples. a. If the DOB you entered is in the future, print “Hello XXXXX, there are XXX days to your Birthday!” b. If the DOB you entered is today, print “Hello XXXXX, happy birthday!” c. If the DOB you entered is in the past, print “Hello XXXXX, your next birthday will be in XXX days.” d. Replace...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT