Home > front end >  Another way of conditioning the query
Another way of conditioning the query

Time:09-20

I saw the block of SQL below in the article in this page:

select @empname=d.Emp_Name from deleted d

How do you put something like @empname=d.Emp_Name in a SELECT statement?? What does it do? Is it another way of conditioning, instead of using WHERE clause?

Plus, it seems to be in SQL Server, but just to be sure, isn't it something that can be done in MySQL or some other DBMS??

CodePudding user response:

You can assign to a variable this way...

But this is probably a mistake. This assignment convention is typically used only when you expect exactly one row. However, the deleted table name indicates a likely trigger, and SQL Server will sometimes batch up individual deletions in a single call to the trigger, such that the table has multiple rows. Therefore this trigger is likely not correctly processing some deletions.

  • Related