Type Title Author Comments Última actualización
Tema de debate UPDATE con JOIN en SQLServer hminguet 6 Hace 2 años 11 meses
Tema de debate UPDATE con JOIN en ORACLE SQL hminguet 17 Hace 4 años 3 meses
Entrada de blog Reseña de 'Haskell Data Analysis Cookbook' Carlos 5 Hace 7 años 6 meses
Tema de debate Contadores y Rangos o funcion Rank() en SQLServer hminguet 1 Hace 8 años 3 meses
Entrada de blog Sorteamos dos inscripciones gratuitas al 10º Forum de Business Intelligence Comunidad-Dataprix 8 Hace 10 años 10 meses
Entrada de blog UPDATE with JOIN in ORACLE hminguet 1 Hace 11 años 11 meses
Tema de debate SQL Server 2008 hminguet 1 Hace 14 años 8 meses

Publicaciones

  • UPDATE with JOIN in ORACLE

    Suppose we want to update in our ORACLE database the costs fields of the fact table FAC_TABLE with the unit cost of our table COSTS.

    We can do this in two ways:

    1. (Slow, but valid for a few data or to sporadic uses)

    update FAC_TABLE ft  set UNIT_COST = (select distinct UNIT_COST from COSTS ct  where (ft.id_article = ct.id_article);

    2. (The best way is this, and the performance is ideal if you have constraints)

    UPDATE ( SELECT ft.UNIT_COST AS old_cost,  ct.UNIT_COST AS new_cost FROM FAC_TABLE ft  INNER JOIN COSTS ct ON ft.id_article ct = ct.id_article) )  SET old_cost = new_cost;

    To the proper functionality of this second option you need a UNIQUE or PRIMARY KEY constraint on ct.id_articulo. 
    If you don't have this constraint, you can use the hint / * + BYPASS_UJVC * / after the word UPDATE (Bypass update join view constraint).

    The performance increase if we have the constraint but even without it, the second option should run quite faster than the first option.

     

  • UPDATE con JOIN en SQLServer

    Supongamos que queremos actualizar en nuestra bbdd SQLServer el campo de costes de la tabla de hechos FAC_TABLE con el coste unitario de nuestra tabla de COSTES.

    UPDATE FAC_TABLE
    SET COSTE_UNITARIO = ct.COSTE_UNITARIO
    FROM COSTES ct
    WHERE FAC_TABLE.id_articulo = ct.id_articulo

     

    Algo más sencillo que en Oracle.

     

    Espero que os ayude.

    Héctor Minguet.

  • UPDATE con JOIN en ORACLE SQL

    Foros IT

    Supongamos que queremos actualizar en nuestra base de datos ORACLE el campo de costes de la tabla de hechos FAC_TABLE con el coste unitario de nuestra tabla de COSTES.

    Con Oracle SQL podemos hacerlo de dos maneras:

    • Consulta Lenta, pero si es para pocos datos o para lanzarlo esporádicamente nos puede valer
    update FAC_TABLE ft set COSTE_UNITARIO =
       (select distinct COSTE_UNITARIO
        from COSTES ct
        where (ft.id_articulo = ct.id_articulo); 

     

    • La mejor manera es esta, y el rendimimento es óptimo si tiene constraints)
    UPDATE (SELECT ft.COSTE_UNITARIO AS old_coste,
                   ct.COSTE_UNITARIO AS new_coste 
            FROM FAC_TABLE ft INNER JOIN COSTES ct ON ft.id_articulo = ct.id_articulo)
           ) SET old_coste = new_coste;

    Para que esta segunda opción funcione necesitamos tener UNIQUE or PRIMARY KEY constraint en ct.id_articulo.

    Si no tienes esta constraint, puedes utilizar el hint /*+BYPASS_UJVC*/ después de la palabra UPDATE (bypass update join view constraint).