SQL 一些技巧

  • 85
  • 0
  • 2016-03-16

一些技巧

A資料表大量更新B資料表

UPDATE Product
SET ProductCategoryCode = o.ProductCategory
FROM OldProduct o JOIN Product p
ON o.SerialNumber = p.SerialNumber

SQL 補錯誤的行數 

USE AdventureWorks;
GO

BEGIN TRY
    -- Generate a divide-by-zero error.
    SELECT 1/0;
END TRY
BEGIN CATCH
    SELECT
        ERROR_NUMBER() AS ErrorNumber,
        ERROR_SEVERITY() AS ErrorSeverity,
        ERROR_STATE() AS ErrorState,
        ERROR_PROCEDURE() AS ErrorProcedure,
        ERROR_LINE() AS ErrorLine,
        ERROR_MESSAGE() AS ErrorMessage;
END CATCH;
GO

 

 

 

既然走了! 就勇往的去 ......