I have a table that captures a bunch of information whenever a user logs into my app. Three of the main fields are username, ip, and datetime. I created a new table (user_ip_table) which has the following columns.
ID (unique auto gen)
username
ip
datetime
I want to create a trigger on the main table to keep track of the last ip address used by a given user. So when a new row is inserted into the main table the trigger will fire and do one of the following.
if username/ip combo is present in user_ip_table then do nothing
if username is present but with a different ip then update the ip address and datetime
if username is not present then insert it with ip and datetime
Is there an easy way to do this? Or do I need to create 3 triggers, one for each case?
Thanks!
Jim
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Fellow title is reserved for select members who demonstrate sustained contributions, industry leadership, and outstanding performance. We will announce the experts being inducted into the Experts Exchange Fellowship during the annual Expert Awards, but unlike other awards, Fellow is a lifelong status. This title may not be given every year if there are no obvious candidates.
The Most Valuable Expert award recognizes technology experts who passionately share their knowledge with the community, demonstrate the core values of this platform, and go the extra mile in all aspects of their contributions. This award is based off of nominations by EE users and experts. Multiple MVEs may be awarded each year.