|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 6:49 PM
Points: 366,
Visits: 689
|
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Yesterday @ 1:01 PM
Points: 9,367,
Visits: 6,463
|
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Saturday, March 16, 2013 9:53 AM
Points: 847,
Visits: 768
|
|
I missed this one but nice question thanks.
I was thinking that the row can be updated since on insert operation with trigger on it: first inserts the row into the table, then the row is added into the INSERTED table, then the trigger actions are executed and finally commit or rollback. But I missed the "updating the row in the INSERTED table" which is not possible. Anyway nice exercise, thanks.
Regards, Iulian
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 1:28 AM
Points: 1,161,
Visits: 727
|
|
Good question, but another lost point for me 
Didn't read the question properly and misunderstood the "INSERTED table" reference. Once I understood that, the answer was easy to find. Bummer.
Question was worded well enough, I was just stupid.
_____________________________________________________________________ "The difficult tasks we do immediately, the impossible takes a little longer"
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354,
Visits: 1,299
|
|
Got this one wrong because I didn't understand the wording of the question.
Is it possible, using a trigger, to update a data row before commiting the insert to a table by first updating the row in the INSERTED table ? What row in the Inserted table? It didn't specify the one that was just inserted. Also, what kind of trigger? Can't you use an update trigger that would update a row before any inserts?
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Yesterday @ 1:01 PM
Points: 9,367,
Visits: 6,463
|
|
cengland0 (1/10/2011)
Got this one wrong because I didn't understand the wording of the question. Is it possible, using a trigger, to update a data row before commiting the insert to a table by first updating the row in the INSERTED table ? What row in the Inserted table? It didn't specify the one that was just inserted. Also, what kind of trigger? Can't you use an update trigger that would update a row before any inserts?
To quote BOL:
DML triggers use the deleted and inserted logical (conceptual) tables. They are structurally similar to the table on which the trigger is defined, that is, the table on which the user action is tried. The deleted and inserted tables hold the old values or new values of the rows that may be changed by the user action
So the INSERTED table is the temporary table maintained by the system.
What kind of trigger? The question asks if it is possible with a trigger. So it is up to you to find out if there is a trigger that can do this. That's the whole point of the question.
How to post forum questions. Need an answer? No, you need a question. What’s the deal with Excel & SSIS?
Member of LinkedIn. My blog at LessThanDot.
 MCSA SQL Server 2012 - MCSE Business Intelligence
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354,
Visits: 1,299
|
|
Koen (da-zero) (1/10/2011)
What kind of trigger? The question asks if it is possible with a trigger. So it is up to you to find out if there is a trigger that can do this. That's the whole point of the question. I understand that you cannot update data in the TEMPORARY INSERTED table. I thought that question asked about Updating any row in the table was that that you inserted the record in -- not the temporary one. I was confused on the definition of "INSERTED table" thinking that could mean the table you just inserted the record in. Understand the issue now?
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Yesterday @ 1:01 PM
Points: 9,367,
Visits: 6,463
|
|
cengland0 (1/10/2011)
Koen (da-zero) (1/10/2011)
What kind of trigger? The question asks if it is possible with a trigger. So it is up to you to find out if there is a trigger that can do this. That's the whole point of the question.I understand that you cannot update data in the TEMPORARY INSERTED table. I thought that question asked about Updating any row in the table was that that you inserted the record in -- not the temporary one. I was confused on the definition of "INSERTED table" thinking that could mean the table you just inserted the record in. Understand the issue now?
I surely understand the issue. I had to read the question a few times in order to get it right. The thing that finally made the trick for me was that INSERTED was in upper case, so I thought it had to be the special temp table.
How to post forum questions. Need an answer? No, you need a question. What’s the deal with Excel & SSIS?
Member of LinkedIn. My blog at LessThanDot.
 MCSA SQL Server 2012 - MCSE Business Intelligence
|
|
|
|
|
SSChasing Mays
      
Group: General Forum Members
Last Login: Wednesday, May 15, 2013 10:09 AM
Points: 648,
Visits: 684
|
|
I understood the question, and I thought it was a good one. I had honestly never considered whether or not the INSERTED table could be updated. I thought it would be pretty cool if it could be, so I answered Yes. Oh well, that's what wishful thinking gets me. 
Ron
----- a haiku...
NULL is not zero NULL is not an empty string NULL is the unknown
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Today @ 3:07 AM
Points: 3,226,
Visits: 64,107
|
|
Koen (da-zero) (1/10/2011)
cengland0 (1/10/2011)
Koen (da-zero) (1/10/2011)
What kind of trigger? The question asks if it is possible with a trigger. So it is up to you to find out if there is a trigger that can do this. That's the whole point of the question.I understand that you cannot update data in the TEMPORARY INSERTED table. I thought that question asked about Updating any row in the table was that that you inserted the record in -- not the temporary one. I was confused on the definition of "INSERTED table" thinking that could mean the table you just inserted the record in. Understand the issue now? I surely understand the issue. I had to read the question a few times in order to get it right. The thing that finally made the trick for me was that INSERTED was in upper case, so I thought it had to be the special temp table.
Yes and I read it as can you manipulate the inserted data. i.e. if I use an INSTEAD of INSERT or INSTEAD of UPDATE trigger and do something like
CREATE TRIGGER T1 ON Table1 INSTEAD OF INSERT AS BEGIN INSERT Table1(columns) SELECT some values, some with formulae FROM INSERTED END
In that case you can manipulate the INSERTED or DELETED data, but yes you can't actually manipulate the data in INSERTED or DELETED.
No biggie, though the only take away I got from this was to learn to read the questions more carefully and try to make sure I'm thinking like the question writer better.
--Mark Tassin MCITP - SQL Server DBA Proud member of the Anti-RBAR alliance. For help with Performance click this link For tips on how to post your problems
|
|
|
|