Добавить комментарий

Изображение пользователя st.

P.S. Код добавления суррогатного ключа

Для справки

ALTER TABLE orders ADD order_id int NULL
GO
UPDATE orders
  SET order_id = T2.rownum
  FROM orders T1 INNER JOIN 
      (SELECT ROW_NUMBER() OVER (ORDER BY 
                    product_code,
                    customer_code,
                    order_type,
                    qty_date
              ) AS rownum, 
              product_code, customer_code, order_type, qty_date
         FROM orders
      ) T2 
      ON T1.product_code = T2.product_code AND
         T1.customer_code = T2.customer_code AND
         T1.order_type = T2.order_type AND
         T1.qty_date = T2.qty_date
GO         
ALTER TABLE orders ALTER COLUMN order_id int NOT NULL
GO
CREATE UNIQUE INDEX AK1_orders ON orders (order_id)