Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can anyone explain what this script in SQL means?

UPDATE trgt
SET trgt.User = dbo.ScrambleEmail ( @Mode, @Key, trgt.[User] )
FROM [company].[User_Group] trgt

I’m a little confused about this update statement. I understand that it is calling an existing function during the update statement but it’s a little different from other update statements. Normally an update statement ends with "where" however this update statement ends with "from". Furthermore "trgt" seems to replace the table name instead

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Missing a WHERE clause means the UPDATE query looks at EVERY ROW. This is usually a mistake, but occasionally it is the intended behavior. With a function call like that, it’s also possible the function is smart enough to return the original value for a lot of the rows.

The trgt identifier is called an alias, and you should be using aliases in nearly all your queries. They often reduce the amount of code you need to write, help disambiguate between similar tables, help distinguish between instances when you need to reference the same table more than once, and have several other benefits.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading