Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Conexión con bases de datos
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Conexión con bases de datos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 25-02-2005
manuelpr manuelpr is offline
Miembro
 
Registrado: nov 2003
Posts: 30
Poder: 0
manuelpr Va por buen camino
Unhappy Como saber si una Tabla existe con Ado

Hola,

Estoy trabajando con MS SQL server 2000 y Delphi 6, conectado con ADO y necesito crear algunas tablas, pero antes debo verificar que estas no existan. Como saber si una tabla existe en una base de datos conectado con ADO.

Saludos
Responder Con Cita
  #2  
Antiguo 25-02-2005
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.325
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Lanza la consulta siguiente:

Código SQL [-]
  Select id from SysObjects where xType='U' and Name='NombreTabla'

Si la tabla con nombre 'NombreTabla' existe te devolverá un registro, si no existe te devolverá 0 registros.

Código SQL [-]
   Select name from SysObjects where xType='U'

te devuelve un registro por cada tabla que existe en la Base de Datos.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
  #3  
Antiguo 28-02-2005
manuelpr manuelpr is offline
Miembro
 
Registrado: nov 2003
Posts: 30
Poder: 0
manuelpr Va por buen camino
Unhappy

Lo probe pero me arroja el siguiente Error : Invalid Object name 'Sysobjects'

Saludos
Responder Con Cita
  #4  
Antiguo 28-02-2005
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.325
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Yo he probado a poner un ADOQuery apuntando a una Base de Datos de SQLServer 2000 con Delphi 6 y con la siguiente SQL:

Código SQL [-]
   Select name from SysObjects where xType='U'

y funciona perfectamente.
Lo he conectado a un DBGrid y muestra todos los registros.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
  #5  
Antiguo 28-02-2005
manuelpr manuelpr is offline
Miembro
 
Registrado: nov 2003
Posts: 30
Poder: 0
manuelpr Va por buen camino
Estube probando : Select id from SysObjects where xType='U' and Name='NombreTabla'

donde especifique el nombre de la tabla y me dio el anterior problema

'NombreTabla' = 'COMUNAS'

Quiero saber si la tabla COMUNAS existe en la base de datosa
Responder Con Cita
  #6  
Antiguo 01-03-2005
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.325
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Ésta consulta debería funcionar; Lánzala y luego pregunta si ADOQuery.EOF es True.
Código SQL [-]
   Select id from SysObjects where xType='U' and Name='COMUNAS'
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 02:10:09.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi