I dont know if I am doing this correctly but here goes...
I want to write an SQL trigger that looks at the current record being inserted and reacts to it but my question is; how do I work with data in this record?
For example, if a new order was being inserted in to the orders table, I want to be able to get 开发者_JS百科the customer name from that order to use in some logic (lets say an email for now).
I had thought about using a SELECT
statment that returned the TOP 1
and ORDER BY DESC
but this seems a bit sloppy to me?
Any advice would be greatly received!
Thanks in advance.
For MS SQL Server, you need to query the inserted table to get the records that are being inserted.
Although, the inserted
table will include all rows being inserted for that transaction. Processing rows on a row by row isn't generally advised in SQL Server. You should be using a set based approach.
Obviously, if only one row is being inserted then there will only one row in the inserted
table.
精彩评论