CREATE TABLE mysql query does not work

0

I have this MySQL query that I try to perform and for some reason it does not work. Can anyone see the error? I have read other questions since yesterday and can not find the answer. I do not find my mistake really.

CREATE TABLE IF NOT EXISTS empleados2(
  'personaId' int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  'nombre' text(11),
  'apellido' text(11),
  'direccion' text(20),
  'cargo' text(20),
  'sueldo_bruto' double(11),
  'cargas_sociales' double(11),
  'vacaciones' double(11),
  'sueldo_neto' double(11)
);

I've also tried this one, but it's not going either:

CREATE TABLE IF NOT EXISTS empleados2(
  'personaId' int(11) NOT NULL AUTO_INCREMENT,
  'nombre' text(11),
  'apellido' text(11),
  'direccion' text(20),
  'cargo' text(20),
  'sueldo_bruto' double(11),
  'cargas_sociales' double(11),
  'vacaciones' double(11),
  'sueldo_neto' double(11),
  PRIMARY KEY('personaId')
);
    
asked by berlot83 11.03.2017 в 15:04
source

1 answer

3

There are 2 main problems you have:

First, single quotes should not be used for the names of the columns. Either you do not use anything, or you can use back ticks . That is, instead of:

'personaId' int(11)

... you can use

'personaId' int(11)

... or

personaId int(11)

The second problem is that the type double can not specify a size. So:

vacaciones double(11)

... is not correct, but should be simply:

vacaciones double

... or maybe your intention was to use another type. In any case, you have to correct the problem in all the columns where you are using type double erroneously.

So once you apply the corrections (using your first attempt as a base), the sentence would be:

CREATE TABLE IF NOT EXISTS empleados2(
    personaId int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, 
    nombre text(11), 
    apellido text(11), 
    direccion text(20), 
    cargo text(20), 
    sueldo_bruto double, 
    cargas_sociales double, 
    vacaciones double, 
    sueldo_neto double);

Demo

    
answered by 11.03.2017 / 15:14
source