Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

Error al crear una vista

Estas en el tema de Error al crear una vista en el foro de Mysql en Foros del Web. Hola, quiero crear una vista con la siguiente sentencia Cita: SELECT t.idvisita, t.fecha_visita, t.nif, r.idempresa, s.clase FROM tbl_visita t, tbl_zona s, tbl_empresa r where r.codigopostal=s.codpostal ...
  #1 (permalink)  
Antiguo 20/02/2006, 11:12
Avatar de Callaghan  
Fecha de Ingreso: enero-2006
Mensajes: 58
Antigüedad: 18 años, 3 meses
Puntos: 1
Error al crear una vista

Hola, quiero crear una vista con la siguiente sentencia
Cita:
SELECT t.idvisita, t.fecha_visita, t.nif, r.idempresa, s.clase
FROM tbl_visita t, tbl_zona s, tbl_empresa r
where r.codigopostal=s.codpostal AND r.centrotrabajo='0' AND t.idempresa=r.idempresa;
La ejecuto con el mysql browser 1.1.15 y me sale bien, pero si le pongo al principio create view vista as..... me da un error de sintaxis(MySql Error 1064).

Que hago mal?
  #2 (permalink)  
Antiguo 20/02/2006, 12:33
Avatar de deadlykyo  
Fecha de Ingreso: noviembre-2005
Ubicación: Cbba - Bolivia
Mensajes: 747
Antigüedad: 18 años, 5 meses
Puntos: 5
puedes poner la sentencia completa del CREATE VIEW que te da error y el error completo ya que con solo el codigo ni idea tengo de que pueda ser, cya
__________________
"El Conocimiento es de todos, no solo de algunos"
  #3 (permalink)  
Antiguo 20/02/2006, 13:31
Avatar de Callaghan  
Fecha de Ingreso: enero-2006
Mensajes: 58
Antigüedad: 18 años, 3 meses
Puntos: 1
Cita:
CREATE VIEW vista
AS SELECT t.idvisita, t.fecha_visita, t.nif, r.idempresa, s.clase
FROM tbl_visita t, tbl_zona s, tbl_empresa r
where r.codigopostal=s.codpostal AND r.centrotrabajo=0 AND t.idempresa=r.idempresa;
Error
Cita:
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 'VIEW vista
AS SELECT t.idvisita, t.fecha_visita, t.nif, r.idempresa, s.clase
F' at line 1
gracias
  #4 (permalink)  
Antiguo 20/02/2006, 13:44
Avatar de deadlykyo  
Fecha de Ingreso: noviembre-2005
Ubicación: Cbba - Bolivia
Mensajes: 747
Antigüedad: 18 años, 5 meses
Puntos: 5
uyy hasta donde veo parece estar correcto, revisaste las restricciones de las vistas, de que no puedes crear de tablas temporales, no pueden haber subconsultas, esas cosas, tal vez sea alguna de ellas, aqui te dejo las restricciones
Cita:
A view definition is subject to the following restrictions:

*

The SELECT statement cannot contain a subquery in the FROM clause.
*

The SELECT statement cannot refer to system or user variables.
*

The SELECT statement cannot refer to prepared statement parameters.
*

Within a stored routine, the definition cannot refer to routine parameters or local variables.
*

Any table or view referred to in the definition must exist. However, after a view has been created, it is possible to drop a table or view that the definition refers to. To check a view definition for problems of this kind, use the CHECK TABLE statement.
*

The definition cannot refer to a TEMPORARY table, and you cannot create a TEMPORARY view.
*

The tables named in the view definition must already exist.
*

You cannot associate a trigger with a view.
cya
__________________
"El Conocimiento es de todos, no solo de algunos"
  #5 (permalink)  
Antiguo 21/02/2006, 17:56
Avatar de Callaghan  
Fecha de Ingreso: enero-2006
Mensajes: 58
Antigüedad: 18 años, 3 meses
Puntos: 1
Hola, creo que el error estaba en que en la version 4.1 de mysql no se pueden hacer vistas, me he pasado a la 5.0 y ya puedo.
Muchas Gracias
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 02:47.