MySQL - Error 1064

 
Vista:

Error 1064

Publicado por Tania (1 intervención) el 06/06/2017 20:29:33
Hola a todos, soy nueva en esto y me gustaría que me pudierais echar una mano para saber cuales son los errores. Gracias

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
create table Fichamedica(
   Fichamedica_ID int unsigned auto_increment,
   Enfermedades int unsigned,
   Tratamiento varchar(2),
   Ultima revision varchar(8),
   primary key (Fichamedica_ID),
   foreign key (Enfermedades) REFERENCES Fichamedica(Enfermedades)
   );
 
create table Relacion_Fmv(
   Fichamedica_ID int unsigned,
   Vacuna_ID int unsigned,
   foreign key (Fichamedica_ID) REFERENCES (Fichamedica),
   foreign key (Vacuna_ID) REFERENCES Vacunas(Vacuna_ID),
   primary key (Fichamedica_ID,Vacuna_ID)
   );
 
 
create table Pedigri(
   Pedigri_ID int unsigned auto_increment,
   Descripcion varchar(10) not null,
   primary key (Pedigri_ID)
   );
 
 
create table Comportamiento(
   Comportamiento_ID int unsigned auto_increment,
   Obediencia varchar(2) not null,
   Agresividad varchar(2) not null,
   Actividad varchar(5) not null,
   Cariñoso varchar(2) not null,
   primary key (Comportamiento_ID)
   );
 
 
   create table PERROS(
   Nombre varchar(15) default 'No name',
   Procedencia varchar(30) default 'Desconocida',
   Fichamedica not null,
   Pedigri varchar(20) not null,
   Edad varchar(2) not null default 'Desconocida',
   Raza varchar(50) not null default 'Desconocida',
   Comportamiento int unsigned not null,
   ID_number int unsigned auto_increment,
   primary key (Nombre)
   foreign key (Fichamedica) REFERENCES PERROS(Fichamedica),
   foreign key (Comportamiento) REFERENCES PERROS(Comportamiento),
   foreign key (Pedigri) REFERENCES PERROS(Pedigri_ID)
   );
 
 
 
  create table Autor(
   Autor_ID int unsigned auto_increment,
   Nombre autor varchar(20) default 'Anonimo',
   Pais varchar(20) default 'Desconocido',
   AñoNac varchar(4) default 'Desconocido',
   primary key (Autor_ID)
   );
 
 create table LIBROS(
   Libros_ID int unsigned auto_increment,
   Autor varchar(20) default 'Anonimo',
   Titulo libro varchar(25) not null,
   Editorial varchar(10)not null,
   Genero not null,
   primary key (Libros_ID),
   foreign key (Autor) REFERENCES LIBROS(Autor)
   );
 
 
 
 
   create table Tipo_ID(
   Tipo_ID int unsigned auto_increment not null,
   Descripcion varchar(13) not null,
   primary key (Tipo_ID)
   );
 
 
   create table PERSONAL(
   DNI varchar(9) not null,
   Tipo_ID int unsigned,
   Nºseguridad social varchar(12) not null,
   Contrato varchar(1000) not null,
   Curriculum varchar(1000) not null,
   Nºcuenta varchar(20) not null,
   Nºtelefono varchar(9) int unsigned,
   Email varchar(20) not null,
   Direccion varchar(20) not null,
   primary key (DNI),
   foreign key (Tipo_ID) REFERENCES PERSONAL(Tipo_ID)
   );
 
 
 
 
 
 
 
  create table Generos(
   Genero_ID int unsigned not null,
   Descripcion varchar(50)
   primary key (Genero_ID)
   foreign key (Genero,Genero) REFERENCES HISTORIAS(Genero),LIBROS(Genero)
   );
 
 
 create table HISTORIAS(
   Nombre varchar(20) not null,
   Titulo hitoria varchar(15) not null,
   Genero not null,
   NºPalabras varchar(3) not null,
   Fecha de subida varchar(10) not null,
   Edicion consurso varchar(10) not null,
   Historia_ID int unsigned,
   primary key (Historia_ID)
   );
 
 
 
 create table MIEMBROS CLUB LECTURA(
   ID_Number int unsigned,
   ID_Reunion int unsigned auto_increment,
   primary key (ID_Number,ID_Reunion)
   );
 
create table USUARIOS(
   ID_Number int unsigned auto_increment,
   Nombre varchar(20) not null,
   Correo varchar(20) ,
   Contraseña varchar(15),
   Nºtelefono varchar(9) not null,
   Token varchar(20),
   Ganador varchar(2) not null,
   Edición varchar(10) default 'No ganador',
   primary key (ID_Number)
   foreign key (ID_Number) REFERENCES USUARIOS(ID_Number),
   foreign key (ID_Number) REFERENCES USUARIOS(ID_Number)
   );
 
 
create table CLUB LECTURA(
   ID_Reunion int unsigned not null,
   Fechas de reunion varchar(10) default 'Sin reunion registrada',
   primary key (ID_Reunion),
   foreign key (ID_Reunion) REFERENCES CLUB LECTURA(ID_Reunion)
   );
 
 
create table TipoAlimento_ID(
   TipoAlimento_ID int unsigned auto_increment,
   Descripcion varchar(50),
   primary key (Alimento_ID)
);
 
create table Clientes(
  Cliente_ID int unsigned auto_increment,
  Alimento_ID int unsigned,
  Cantidad pedida varchar(60) not null,
  ID_Number int unsigned,
  primary key (Cliente_ID)
  );
 
 create table ALIMENTOS(
   Alimento_ID int unsigned auto_increment,
   TipoAlimento_ID int unsigned,
   Fecha caducidad varchar(10) not null,
   Proveedor varchar(20) not null,
   Cantidad varchar(3) not null,
   Precio_unitario varchar(5) not null,
   primary key (Alimento_ID),
   foreign key (Alimento_ID) REFERENCES ALIMENTOS(Alimento_ID)
   );
 
 
 
create table Modelo(
   Modelo_ID int unsigned auto_increment,
   Descripcion varchar(50)
);
 
 create table Tecnologia(
   Tecnologia_ID int unsigned auto_increment,
   Marca varchar(30) not null,
   Memoria RAM varchar(30) not null,
   Disco duro varchar(30) not null,
   primary key (Tecnologia_ID)
   );
 
 
create table MOBILIARIO(
   Mobiliario_ID int unsigned auto_increment,
   Proveedor varchar(20) not null,
   Estado varchar(100) default 'Buen Estado',
   Tecnologia int unsigned,
   Modelo int unsigned,
   primary key (Mobiliario_ID),
   foreign key (Modelo) REFERENCES MOBILIARIO(Modelo),
   foreign key (Tecnologia) REFERENCES MOBILIARIO(Tecnologia)
);

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'revision varchar(8),
primary key(Fichamedica_ID),
foreign key(Enfermedades' at line 5
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(Fichamedica),
foreign key (Vacuna_ID) REFERENCES Vacunas(Vacuna_ID),
prim' at line 4
Query OK, 0 rows affected (0.36 sec)

Query OK, 0 rows affected (0.34 sec)

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'not null,
Pedigri varchar(20) not null,
Edad varchar(2) not null default '' at line 4
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'autor varchar(20) default 'Anonimo',
Pais varchar(20) default 'Desconocido',
' at line 3
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'libro varchar(25) not null,
Editorial varchar(10)not null,
Genero not nu' at line 4
Query OK, 0 rows affected (0.41 sec)

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'social varchar(12) not null,
Contrato varchar(1000) not null,
Curriculum v' at line 4
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(Genero_ID)
foreign key (Genero,Genero) REFERENCES HISTORIAS(Genero),LIBROS(G' at line 4
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'hitoria varchar(15) not null,
Genero not null,
NºPalabras varchar(3) not' at line 3
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CLUB LECTURA(
ID_Number int unsigned, ' at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'foreign key (ID_Number) REFERENCES USUARIOS(ID_Number),
foreign key (ID_Numbe' at line 11
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LECTURA(
ID_Reunion int unsigned not null,
Fechas de reunion varchar(10) d' at line 1
ERROR 1072 (42000): Key column 'Alimento_ID' doesn't exist in table
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'pedida varchar(60) not null,
ID_Number int unsigned,
primary key (Cliente_' at line 4
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'caducidad varchar(10) not null,
Proveedor varchar(20) not null,
Cantidad' at line 4
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'RAM varchar(30) not null,
Disco duro varchar(30) not null,
primary key (Te' at line 4
ERROR 1215 (HY000): Cannot add foreign key constraint
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 953
Oro
Ha mantenido su posición en MySQL (en relación al último mes)
Gráfica de MySQL

Error 1064

Publicado por leonardo_josue (414 intervenciones) el 06/06/2017 20:55:59
Hola Tania:

¿Te tomaste al menos un tiempo para tratar de investigar por tu cuenta qué errores son los que te están marcando? una cosa es que seas novata y no tengas muchos conocimientos de MySQL y otra muy distinta es que no tengas iniciativa para tratar de ver que estás haciendo mal...

Por ejemplo, con este código:

1
2
3
4
5
6
7
8
CREATE TABLE Fichamedica(
Fichamedica_ID INT UNSIGNED AUTO_INCREMENT,
Enfermedades INT UNSIGNED,
Tratamiento VARCHAR(2),
Ultima revision VARCHAR(8),
PRIMARY KEY (Fichamedica_ID),
FOREIGN KEY (Enfermedades) REFERENCES Fichamedica(Enfermedades)
);

Si lo ejecutas te arroja los siguientes errores:

Primero:

1
2
3
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'revision varchar(8),
primary key(Fichamedica_ID),
foreign key(Enfermedades' at line 5

entonces tienes que revisas la parte que te indica el error, cerca de "revisión varchar(8)"... a simple vista se observa que estás poniendo como nombre de campo "ultima revision", lo cual NO ESTÁ PERMITIDO PORQUE TIENES UN ESPACIO EN BLANCO... para evitar este error tienes dos opciones, quitas el espacio o lo sustituyes por otro caracter, por ejemplo el guión de piso (_)

1
2
3
ultima_revision VARCHAR(8),
o
ultimarevisión  VARCHAR(8),

Segundo:

1
2
Error Code : 1215
Cannot add foreign key constraint

De entrada tienes un HORROR (por no decir ERROR) de sintaxis, es decir tienes esto:

1
2
3
4
CREATE TABLE Fichamedica(
...
FOREIGN KEY (Enfermedades) REFERENCES Fichamedica(Enfermedades)
...

por lo tanto ESTÁS TRATANDO DE HACER UNA LLAVE FORÁNEA PERO HACES REFERENCIA A LA MISMA TABLA... la sintaxis indica que después de FOREIGN KEY pones el nombre del campo de la tabla que estás creando que hace referencia a una llave foránea, después de REFERENCE debes de colocar EL NOMBRE DE LA TABLA Y EL CAMPO A LA QUE HACE REFERENCIA...

Puedo suponer que tienes una tabla ENFERMEDADES y por lo tanto quieres hacer referencia a esa tabla, por lo tanto la sintaxis debe ser así:

1
2
3
4
CREATE TABLE Fichamedica(
...
FOREIGN KEY (Enfermedades) REFERENCES Enfermedades(Enfermedades)
...

El resto de los errores son similares, date un tiempo de investigarlos y tratar de resolverlos, si tienes problemas, postea UNO POR UNO cuáles son los esos casos, no nos llenes de código el post y trata de ser PRECISA Y CONCISA.

Saludos
Leo.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar