if(@errorNumber==547){Console.WriteLine("Foreign key violation error occurred.");}else{Console.WriteLine("An error occurred.");} 1. 2. 3. 4. 5. 6. 7. 8. 总结 使用SQL Server error_number函数可以帮助开发者更好地理解和处理错误。本文详细介绍了使用error_number函数的步骤,并提供了相关的代码...
TRY...CATCH 也支援 ERROR_NUMBER 函數,ERROR_NUMBER 函數並不限於在緊接於產生錯誤的陳述式之後的陳述式中傳回錯誤號碼。如需詳細資訊,請參閱<TRY...CATCH (Transact-SQL)>。 範例 A. 利用 @@ERROR 來偵測特定錯誤 下列範例利用 @@ERROR 來檢查 UPDATE 陳述式的 CHECK 條件約束違規 (錯誤號碼 547)。
TRY...CATCH 也支持 ERROR_NUMBER 函数,但不限制该函数在语句产生错误后立即在语句中返回错误号。有关详细信息,请参阅 TRY...CATCH (Transact-SQL)。 示例 A. 用 @@ERROR 检测一个特定错误 以下示例用 @@ERROR 在 UPDATE 语句中检测约束检查冲突(错误 #547)。 复制 USE AdventureWorks2008R2; GO UPDATE ...
IF ERROR_NUMBER() = 2627 -- Duplicate key violation BEGIN PRINT 'Primary Key violation'; END ELSE IF ERROR_NUMBER() = 547 -- Constraint violations BEGIN PRINT 'Constraint violation'; END ELSE BEGIN PRINT 'Unhandled error'; END; IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION; END CATCH; 1. 2...
Msg 547, Level 16, State 0, Line 11 The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Products_Categories". The conflict occurred in database "TSQL2012", table "Production.Categories", column 'categoryid'. Error number ...
This article contains error message numbers (between the range 0 and 999) and their description, which is the text of the error message from the sys.messages catalog view. Where applicable, the error number is a link to further information.For the full range of error numbers,...
ERROR_NUMBER() = 547 BEGIN PRINT ' Handling CHECK/FK constraint violation...' END ELSE IF ERROR_NUMBER() = 515 BEGIN PRINT ' Handling NULL violation...' END ELSE IF ERROR_NUMBER() = 245 BEGIN PRINT ' Handling conversion error...' END ELSE BEGIN PRINT ' Handling unknown error...' ...
DELETE FROM Customers WHERE customerid = 'DUMMY' UPDATE Customers SET customerid = 'GLDRL' WHERE customerid = 'GNDLF' .Net SqlClient Data Provider: Msg 547, Level 16, State 0, Line 1 UPDATE statement conflicted with COLUMN FOREIGN KEY constraint 'FK_Orders_Customers'. The conflict occurred...
Can't Enable Foreign Key Constraint (Msg 547, Level 16, State 0, Line 15) Can't perform emptyfile operation on .mdf? Can't select DISTINCT values with XML datatype. Can't use Begin Transaction before a WITH Cancel Rollback Cannot ALTER 'dbo.fn_GetDate' because it is being referenced...
<12.31.2015 12:40:37> ERROR 2015-12-31 12:40:37 Database Error: error number=547 <12.31.2015 12:40:37> ERROR 2015-12-31 12:40:37 Error Message: The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "fk_task_rsrc". The conflict occurred in database "PMDB1", table ...