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.
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]')
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...
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 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
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...
Write CREATE TABLE and INSERT INTO statements in order to create and populate five tables in...
Write CREATE TABLE and INSERT INTO statements in order to create and populate five tables in Oracle’s SQL*Plus.The information you need about the database ARE IN THE CHARTS BELOW. Each worksheet includes the following information about its associated table: ➢ Column names (for example, the jr_order table contains the orderID, customerID, orderDate, orderStatus, and orderShippedDate columns); ➢ Column data types (for example, orderID is INT, orderStatus is VARCHAR2(2), etc.); ➢ Column constraints, if any (for example, orderID in the jr_order...
Question 1: Part 1 Write SQL statements for the following queries from the ‘EMPLOYEE’ table in...
Question 1: Part 1 Write SQL statements for the following queries from the ‘EMPLOYEE’ table in the WPC Database in MySQL: Display all records from the Employee table for employees working in the “Marketing” department. Display all records from the Employee table for employees working in the “Marketing” department OR “Finance” Department. Display the Last Names of all employees such that each last name appears only once. Display all the attributes for employees whose employee number is less than 10....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT