-2

I have two date columns in one table, i.e. onlineRegistrationCloseDate and onlineRegistrationFixesDate. And for second date column I want to add one day to onlineRegistrationFixesDate column's value. Like if user has entered 2017-02-01 in onlineRegistrationCloseDate then automatically the date for onlineRegistrationFixesDate will be inserted as "2017-02-02".

I tried to set Date_add(Select onlineRegistrationCloseDate , INTERVAL 1 DAY) like this default value of second column but i am getting some error, I am using workbench for it.

Please help me how I can set default value of second column on the based of first column's value.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ram Singh
  • 6,664
  • 35
  • 100
  • 166

1 Answers1

1

create BEFORE INSERT TRIGGER

SET onlineRegistrationFixesDate = new.onlineRegistrationCloseDate + INTERVAL 1 DAY
phoniq
  • 228
  • 1
  • 5
  • do i need to use trigger for it???????????? – Ram Singh Feb 02 '18 at 10:27
  • Yes, you do need to use a trigger, you cannot use an expression based on another column as a default value in MySQL, I'm not aware of an RDBMS that will let you do this without a trigger. You also only need to use one question mark. – DaveRandom Feb 02 '18 at 10:32