Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Coloboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #2  
Antiguo 16-01-2015
Avatar de duilioisola
[duilioisola] duilioisola is offline
Miembro Premium
 
Registrado: ago 2007
Ubicación: Barcelona, España
Posts: 1.806
Poder: 22
duilioisola Es un diamante en brutoduilioisola Es un diamante en brutoduilioisola Es un diamante en bruto
No mencionas la base de datos que deseas utilizar. Supondré por tanto que utilizas Firebird o MySQL. En ese caso no puedes controlar la restricción que mencionas mediante FKs. Deberías hacerlo mediant triggers.
Código SQL [-]
CREATE TRIGGER TABLE3_BI0
as
begin
   if (tipo = 1) then
   begin
      if (not exists(select id_Table1 from table1 where id_Table1 = new.idReferencia)) then
         exception ERR_NO_EXISTE_REF;
   end

   if (tipo = 2) then
   begin
      if (not exists(select id_Table2 from table2 where id_Table2 = new.idReferencia)) then
         exception ERR_NO_EXISTE_REF;
   end
end

CREATE TRIGGER TABLE3_BU0
as
begin
   if ((new.idReferencia <> old.idReferencia) or (new.tipo <> old.tipo)) then
   begin 
      if (tipo = 1) then
      begin
         if (not exists(select id_Table1 from table1 where id_Table1 = new.idReferencia)) then
            exception ERR_NO_EXISTE_REF;
      end

      if (tipo = 2) then
      begin
         if (not exists(select id_Table2 from table2 where id_Table2 = new.idReferencia)) then
            exception ERR_NO_EXISTE_REF;
      end
   end
end
Responder Con Cita
 



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

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Problema Foreign key franfl Firebird e Interbase 2 27-05-2008 19:38:03
violation of Foreign Key JulioGO Firebird e Interbase 2 27-06-2006 00:33:24
foreign key clanmilano Conexión con bases de datos 4 03-11-2005 03:21:19
Foreign key fjardelphi Firebird e Interbase 2 20-12-2004 16:05:39
uso de FOREIGN KEY jzginez Firebird e Interbase 2 22-04-2004 23:20:25


La franja horaria es GMT +2. Ahora son las 04:47:57.


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