A
A
Alexey Sh2015-08-31 11:24:51
Database
Alexey Sh, 2015-08-31 11:24:51

Is there a difference in the mechanisms of working through the interface and through the script in MSSQL Server Management Studio?

All good health!
A very specific problem arose in connection with the use of MS SQL Server Management Studio 12.0.4100.1 DBMS
Background:
1) I created a trigger for an update operation for a table, the trigger simply logs the updated data to the log table, the script is something like this:

ALTER trigger [dbo].[refKartParams_ins_trigger] on [dbo].[RefKartParams]
  for insert,update
as
  begin
  if (not exists (select 1 from deleted where id in (select id from inserted)))
    begin
      insert into dbo.RefKartParams_log
          (ParamType
          ,PartName
          ,FormForEditName
          ,Tablename
          ,DateType
          ,idChangedParam
          ,typeOfChange)
      select ParamType
          ,PartName
          ,FormForEditName
          ,Tablename
          ,DateType
          ,id
          ,'ins'
      from inserted
  end
  else
    begin
      insert into dbo.RefKartParams_log
          (ParamType
          ,PartName
          ,FormForEditName
          ,Tablename
          ,DateType
          ,idChangedParam
          ,typeOfChange)
      select ParamType
          ,PartName
          ,FormForEditName
          ,Tablename
          ,DateType
          ,id
          ,'upd'
      from inserted
    end

  end

2) I decided to check, opened the table in the editor, through the right button on the table - "change"
3) Edited the data, pressed Enter. Then I got the error "The row value (s) updated or deleted either do not make the row unique or they alter multiple rows (2 rows)"
4) I was surprised. Indeed, in the log table, I do not have a check for the uniqueness of the inserted data (this is a log!), There is only a unique record ID in the log (although the error appeared before I made it). If the trigger is disabled, then it does not display errors, everything is quietly edited.
And now, miraculous miracles, if you just open a window and write a script for updating some line in it, then everything works - the line is updated and the changes get into the log as they should.
"Dest is fantastic!"
Maybe there are differences in the work of the interface method of updating data in strings and the script method?
(There are suspicions that the trick is that when you do update ... set DateType=... where id=... from the script, then the update operation is triggered, and if from the interface, then delete + insert, and if insert does not work , then the rollback of the entire transaction rollback tran is triggered, and the insert of a new value may not work if there is, for example, a clustered index)
Who faced this? The studio was first set to Russian (I still sin on this), switched to English - the same picture with an error.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Georgy Grigoriev, 2015-09-10
@IamKarlson

Turn on the profiler and see how the update goes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question