Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8596687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:44:19+00:00 2026-06-12T00:44:19+00:00

This update will fail as ID is Identity But I am getting direct error

  • 0

This update will fail as ID is Identity

But I am getting direct error message.
I am getting none of the PRINT statements.

How do I use @@ERROR?
Using SSMS.
Would you call this a script or a query?

PRINT   'start';
DECLARE @ErrorVal INT;
UPDATE IndenText SET ID = 7;
SELECT @ErrorVal = @@ERROR;
PRINT @ErrorVal;
IF @ErrorVal <> 0
BEGIN
    PRINT N'A error caught.';
END
PRINT 'done';

This also does not work from me

PRINT   'start';
DECLARE @ErrorVal INT;
BEGIN TRY
    UPDATE IndenText SET ID = 7;
    SELECT @ErrorVal = @@ERROR;
    PRINT @ErrorVal;
END TRY
BEGIN CATCH
    IF @@ERROR <> 0
    BEGIN
        PRINT N'A error caught.' + @@ERROR;
    END
END CATCH
PRINT 'done';

I get
Msg 8102, Level 16, State 1, Line 4
Cannot update identity column ‘ID’.

As Martin stated it was a compile error.
Created a constraint that would not be a compile error.
And got the @@ERROR to process.

PRINT   'start';
DECLARE @ErrorVal INT;
DECLARE @newVal INT;
select  @newVal = -1;
BEGIN TRY
    update Twaste1 set ID = @newVal ;
    PRINT 'End Try';
END TRY
BEGIN CATCH
    Select @ErrorVal = @@ERROR;
    PRINT 'Begin Catch';
    IF @ErrorVal <> 0
    BEGIN
        PRINT CAST(@ErrorVal as varchar(30));
        PRINT N'A error caught.';
    END
END CATCH
PRINT 'done'

;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:44:20+00:00Added an answer on June 12, 2026 at 12:44 am

    I would suggest using TRY... CATCH instead. This will allow you to capture and examine the error thrown.

    UPDATE:

    I believe Martin already explained why this doesn’t work in his comments to the original question, but I’ll add a reference to the MSDN TRY... CATCH article:

    The following types of errors are not handled by a CATCH block when
    they occur at the same level of execution as the TRY…CATCH construct:

    • Compile errors, such as syntax errors, that prevent a batch from running.
    • Errors that occur during statement-level recompilation, such as object name resolution errors that occur after compilation because
      of deferred name resolution.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for the double post, I will update this question if I can't get
I have a Method name update, this will be called depending on the boolean
I have a problem when trying to execute this update statement (below) using C#
The update statement is like this UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value However
Please help me with this update query. I COMPLETELY understand how redundant this is
I need to position this update button on www.euroworker.no/order (you'll have to add an
I have this update statement: mysql_query (UPDATE loan SET loan_reff_id='$_POST[loan_reff_id]', commit_date='$_POST[commit_date]',app_loan_type='Tertiary Loan', app_ln_amnt='$_POST[app_ln_amnt]', institution_name='$_POST[institution_name]',
Hello I need to do something like this: UPDATE tbl SET pozn=CONCAT(pozn, '+attach_str+') WHERE
I know that in standard SQL you can do this: update top (100) table1
I have an if statement that needs to look like this: UPDATE $(input#textbox).keypress(function(e){ key==e.which;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.