1

CREATE TABLE pegawai (idpegawai char (6) not null default ' ',
namadepan varchar (20) default null,
namabelakang varchar (25) not null default ' ',
email varchar (25) not null default ' ',
telepon varchar (20) default null,
tglkontrak date not null default ' ');

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''not null')' at line 6

but I want results like this, can you help me? enter image description here

Fan
  • 11
  • 3
  • 1
    Are you sure that the `date` data-type can have a default value of a single space? Maybe this is relevant? https://stackoverflow.com/questions/28805705/how-to-set-default-value-of-date-not-datetime-timestamp-column-to-current-date – Abra May 20 '20 at 04:40
  • When I run this I get "Invalid default value for 'tglkontrak'". – tadman May 20 '20 at 04:43
  • Remove `DEFAULT ' '` for `tglkontrak` column. See https://dba.stackexchange.com/a/267480/150107. – Akina May 20 '20 at 04:46
  • `' '` is not "empty", it has one space. Nor is it `NULL`. – Rick James Jun 02 '20 at 03:31

1 Answers1

1

In your query, you have mentioned whitespace as default value for date field tglkontrak. Date field can accept either NULL or a valid date

if you can have it as null then

CREATE TABLE pegawai (idpegawai char (6) not null default ' ',
namadepan varchar (20) default null,
namabelakang varchar (25) not null default ' ',
email varchar (25) not null default ' ',
telepon varchar (20) default null,
tglkontrak date);

else

CREATE TABLE pegawai (idpegawai char (6) not null default ' ',
namadepan varchar (20) default null,
namabelakang varchar (25) not null default ' ',
email varchar (25) not null default ' ',
telepon varchar (20) default null,
tglkontrak date not null);
Akhilesh Mishra
  • 5,876
  • 3
  • 16
  • 32
  • 1
    *`tglkontrak date not null default '0000-00-00'`* This may contradict with NO_ZERO_DATE and/or NO_ZERO_IN_DATE server SQL mode setting(s). [fiddle](https://dbfiddle.uk/?rdbms=mariadb_10.4&fiddle=71d47d574547f8897dacd55f2c0544e1). – Akina May 20 '20 at 04:47
  • That's correct. it will if strict SQL mode is enabled – Akhilesh Mishra May 20 '20 at 04:50
  • but I want results like this, can you help me? https://i.stack.imgur.com/w6zNw.png – Fan May 20 '20 at 04:58
  • Your edition is not correct - strict mode does not interfere with the problem. See [fiddle](https://dbfiddle.uk/?rdbms=mariadb_10.4&fiddle=39bb35cc9d2bfdf340a694a6e32d67dd). – Akina May 20 '20 at 04:58
  • instead of `tglkontrak date` use `tglkontrak date not null` – Akhilesh Mishra May 20 '20 at 05:00