1

getting an syntax error in mysql

CREATE SEQUENCE users_id_seq;
CREATE TABLE users (
  id INTEGER PRIMARY KEY NOT NULL DEFAULT NEXTVAL ('users_id_seq'),
  name VARCHAR(50) NOT NULL,
  active BOOLEAN NOT NULL DEFAULT true,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

create a table with id sequence but getting syntax error

shaik azar
  • 29
  • 2

1 Answers1

0

The errors you're getting are due to the CREATE SEQUENCE statement, which is Oracle syntax for generating auto-incremental values.

In MySQL you can use the AUTO_INCREMENT keyword inside the table creation statement as follows:

CREATE TABLE users (
  id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,
  name VARCHAR(50) NOT NULL,
  active BOOLEAN NOT NULL DEFAULT true,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
);

Check the demo here.

lemon
  • 14,875
  • 6
  • 18
  • 38