Hello, I'm creating a TRIGGER where I should do a series of treatments after an UPDATE in a table in SQLServer. In this TRIGGER, I need to set some variables so I can work with them in the rest of the script, like this:
CREATE TABLE foo (
id INT NOT NULL IDENTITY(1,1) PRIMARY KEY,
nome NVARCHAR(100) NOT NULL,
telefone NVARCHAR(30) NOT NULL DEFAULT '',
email NVARCHAR(100) NOT NULL DEFAULT ''
);
GO
CREATE TRIGGER [TR_foo_onUpdate] ON foo AFTER UPDATE AS
BEGIN
SET NOCOUNT ON;
DECLARE @id BIT = (SELECT id FROM inserted),
@nome NVARCHAR(100) = (SELECT nome FROM inserted),
@telefone NVARCHAR(30) = (SELECT telefone FROM inserted),
@email NVARCHAR(100) = (SELECT email FROM inserted);
/* continuação do script aqui... */
END
My question is this, is there any way I can do the declare without having to do 4 SELECT
's? The question is more for optimization because it can certainly be used in many other scripts ...