Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Cannot creat database tabele: syntax error

I’m trying to create mysql db table as below, but it got a syntax error at line 4.

CREATE TABLE findable_drivers (
id BIGINT NOT NULL AUTO_INCREMENT,
driver_id BIGINT NOT NULL,
current_role VARCHAR(100) NOT NULL, #here
lat DOUBLE NOT NULL,
lng DOUBLE NOT NULL,
findable BOOLEAN  DEFAULT 0 NOT NULL,
CONSTRAINT findable_drivers_PK PRIMARY KEY (id),
CONSTRAINT findable_drivers_UN UNIQUE KEY (driver_id),
CONSTRAINT findable_drivers_driver_FK FOREIGN KEY (driver_id) REFERENCES driver(id)
)
ENGINE=InnoDB
DEFAULT CHARSET=latin1
COLLATE=latin1_swedish_ci ;

the error description:

#1064 – 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 ‘current_role VARCHAR(100) NOT NULL,
lat DOUBLE NOT NULL,
lng DOUBLE NOT N…’ at line 4

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

CURRENT_ROLE() is actually a MySQL/MariaDB system function which returns active roles for the current session. So in your CREATE TABLE statement, the database thinks you are trying to call this function. You should call the current_role column something else. If you must stick with this name, then will have to forever refer to it using backticks:

CREATE TABLE findable_drivers (
    id BIGINT NOT NULL AUTO_INCREMENT,
    driver_id BIGINT NOT NULL,
    `current_role` VARCHAR(100) NOT NULL,  -- must use backticks here
    lat DOUBLE NOT NULL,
    lng DOUBLE NOT NULL,
    findable BOOLEAN  DEFAULT 0 NOT NULL,
    CONSTRAINT findable_drivers_PK PRIMARY KEY (id),
    CONSTRAINT findable_drivers_UN UNIQUE KEY (driver_id),
    CONSTRAINT findable_drivers_driver_FK FOREIGN KEY (driver_id) REFERENCES driver(id)
) ENGINE=InnoDB
  DEFAULT CHARSET=latin1
  COLLATE=latin1_swedish_ci;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading