sql >> Database teknologi >  >> RDS >> Sqlserver

Problem med samtidige SQL Server-transaktioner

Gør det hele i ét med noget komponerbart DML?

INSERT INTO order_item (item_no, order_id)
SELECT 
    X.item_no, @order_id
FROM
    (
    MERGE INTO items AS tgt
    USING
      (SELECT TOP (@whatever) item_no
       FROM items
       WHERE status = 'Unused'
      ) AS src ON tgt.item_no = src.item_no
    WHEN MATCHED
      UPDATE SET status = 'Used'
      OUTPUT $action as action, item_no -- $action needed for more complex stuff
    ) AS X
-- WHERE action = 'UPDATE' -- needed for more complex stuff


  1. mysql join ON og AND for at laravel veltalende

  2. Ingen database valgt fejl i PHP med MySQLi

  3. Undgå SQL-injektion i et brugergenereret SQL-regex

  4. Oracle 12c Ubuntu 17.04 Installationsfejl