Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good way to use table alias in Update statement?

Tags:

sql-server

People also ask

Can you use a table alias in an update statement?

I've found a very common belief among users of T-SQL (both DBAs and Developers) is that you can't use an alias with the UPDATE statement. As best I can tell the reason for this is because of a simple misunderstanding of the UPDATE command syntax.

What is the correct way to assign an alias for a table?

The basic syntax of a table alias is as follows. SELECT column1, column2.... FROM table_name AS alias_name WHERE [condition];

Does table aliases improve performance?

The alias doesn't affect performance in any practical or measurable way at all (italics added on edit). That is, it would add a barely (if it all) measurable delay to query compilation. Once compiled (and re-used), it has no effect.

What is a table alias how it is useful?

SQL aliases are used to give a table, or a column in a table, a temporary name. Aliases are often used to make column names more readable. An alias only exists for the duration of that query. An alias is created with the AS keyword.


UPDATE ra 
   SET ra.ItemValue = rb.ItemValue
  FROM dbo.Rates ra
 INNER JOIN dbo.Rates rb
         ON ra.ResourceID = rb.ResourceID
WHERE ra.PriceSched = 't8'
  AND rb.PriceSched = 't9';

This might help in improving performance.


Table alias in Update Query in T-SQL( Microsoft SQL) . for MS SQL Server 2008 R2 it's work just fine

UPDATE A_GeneralLedger  set ScheduleId=g.ScheduleId
from A_GeneralLedger l inner join A_AcGroup g on g.ACGroupID=l.AccountGroupID