What causes SQL Server to return the message 'The statement has been terminated'?

前端 未结 3 1875
梦如初夏
梦如初夏 2021-01-18 05:59

I have a very simple INSERT statement being executed from a PHP script running on a Linux Apache web server. I can run the query fine from within SQL Management Studio and

3条回答
  •  死守一世寂寞
    2021-01-18 06:22

    You can use the code in the message to know which is the error. For example:

    [2627: The statement has been terminated.]

    In this case, the error code is 2627, so if you execute the sql below you'll know the message

    SELECT msg.text
      FROM sys.messages msg 
     INNER JOIN sys.syslanguages lng ON lng.msglangid = msg.language_id
     WHERE msg.message_id = 2627
       AND lng.alias = 'English'
    

    Violation of %ls constraint '%.*ls'. Cannot insert duplicate key in object '%.*ls'. The duplicate key value is %ls.

    This is a way to know the right message error. In my example the error is violation of primary key

提交回复
热议问题