-1

MYSQL

create table Emp
( 
 Eid int primary key,
 Ename varcharacter(20) not null,
 Eage int,
 Eadd varcharacter(21) default ' Cairo ',
 HireDate date DEFAULT  ***CURDATE( )***,
 
);

I want to set a default value in the hiring date to be the current date if no date is written in the column but nothing works CURRENT_DATE and CURDATE()

4
  • You have a couple of typos in your code; check the documentation for the correct CREATE TABLE syntax.
    – mustaccio
    Commented Nov 20, 2023 at 18:52
  • Sorry, I do not get it .. what is the documentation for the correct CREATE TABLE syntax? Commented Nov 20, 2023 at 19:06
  • Also, see this: MySQL error - creating table and trying current date as default
    – prasad_
    Commented Nov 21, 2023 at 4:55
  • " ( " is not valid at this Position ... the same error when tying any of those syntaxes (CURDATE()) or (CURRENT_DATE()) or (CURRENT_DATE) Commented Nov 21, 2023 at 20:54

1 Answer 1

2

https://dev.mysql.com/doc/refman/8.0/en/create-table.html

Probably just missing parentheses around the expression:

HireDate date DEFAULT (CURDATE( )),
1
  • " ( " is not valid at this Position Commented Nov 21, 2023 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.