Hi, I'm new to mysql, I'm trying to create a table according to the following statement: Create a table STUDENTS with the columns: student number (integer with three digits, unsigned, filled with zeros and autoincremented), name, surname, address, ID . Set restrictions: student number is primary key; name, surnames, dni are not null, and dni does not admit repeated values.
At the moment I have this:
but when executing the table, it gives me the error Invalid default value for 'Nro_ALU'
CREATE TABLE ALUMNOS(
NRO_ALU TINYINT AUTO_INCREMENT DEFAULT 000,
NOMBRE VARCHAR(50) NOT NULL,
APELLIDOS VARCHAR(50) NOT NULL,
DIRECCION VARCHAR(50) ,
DNI VARCHAR(10) UNIQUE NOT NULL,
PRIMARY KEY (NRO_ALU)
)
ENGINE = InnoDB;
The requirement would be satisfied in this way:
TINYINT
UNSIGNED
ZEROFILL
AUTO_INCREMENT
Set restrictions:
PRIMARY KEY (NRO_ALU)
.... NOT NULL
in each of themUNIQUE
Tu
DEFAULT 000
doesn't make any sense in a columnAUTO_INCREMENT
, justTINYINT
for this case, or if you want with aINT(3)
.Test code:
Departure:
I put a screenshot because the zerofills are not seen in the fiddle: