0

MySQL is telling syntax error: unexpected 'DEFAULT' in my script below. How come is this?

  USE `neoweb`;

 ALTER TABLE `neoweb`.`ActivationRequests` ADD  CONSTRAINT 
`DF_ActivationRequests_CreatedDate` DEFAULT (utc_timestamp()) FOR `CreatedDate`;
denny
  • 2,084
  • 2
  • 15
  • 19
Larry
  • 1
  • 1
    In MySQL, CONSTRAINTs are used to define primary keys and foreign keys. You have to state what kind of constraint you want to add before setting a default value to the field. For more info about constraints: https://dev.mysql.com/doc/refman/5.7/en/constraints.html – Marc-Antoine Parent Feb 07 '17 at 04:37

1 Answers1

0

Oh... DEFAULT is not a constraint.

Anyway your syntax seems wrong.

ALTER TABLE TABLENAME   
ADD CONSTRAINT [ PRIMARY KEY/ FOREIGN KEY/ UNIQUE/ CHECK ]  

is the minimum syntax for adding constraint.

You seem to have default value on your column. How to set default value using ALTER statement is answered here

Community
  • 1
  • 1
Kishor Pawar
  • 3,386
  • 3
  • 28
  • 61