I have this sql script that creates a table in my MySql database.
CREATE TABLE USER_ACCOUNT
(ID DECIMAL(10) NOT NULL,
USERNAME VARCHAR (50) NOT NULL,
PASSWORD VARCHAR (25) NOT NULL,
EMAIL VARCHAR (50) NOT NULL,
FIRST_NAME VARCHAR (25) NULL DEFAULT NULL,
MIDDLE_NAME VARCHAR (25) NULL DEFAULT NULL,
LAST_NAME VARCHAR (25) NULL DEFAULT NULL,
CREATE_DATE TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP);
ALTER TABLE USER_ACCOUNT
ADD CONSTRAINT USER_ACCOUNT_PK_ID
PRIMARY KEY (ID);
ALTER TABLE USER_ACCOUNT
ADD CONSTRAINT USER_ACCOUNT_UK_USERNAME
UNIQUE (USERNAME);
ALTER TABLE USER_ACCOUNT
MODIFY COLUMN ID DECIMAL(10) NOT NULL AUTO_INCREMENT;
I understand that AUTO_INCREMENT has to be added to a KEY. I am trying to add AUTO_INCREMENT to the primary key ID but the line
ALTER TABLE USER_ACCOUNT
MODIFY COLUMN ID DECIMAL(10) NOT NULL AUTO_INCREMENT;
Has the following syntax error:
Syntax error: unexpected 'DECIMAL' (decimal)
And then has this error when the script is run:
Error Code: 1063. Incorrect column specifier for column 'ID'
What's going on with my statement? I've looked all over online and it looks like the correct syntax.
DECIMALdata type. I don't think you can applyAUTO_INCREMENTto a column of this type. TryBIGINTinstead.BIGINT