Is it always useful to use aliases in sql connections or nested queries?

Is it always better to use -

Select E.Id,D.DeptName from Employee E join Dept D on E.DeptId=D.Id

instead

Select Employee.Id,Dept.DeptName from Employee join Dept on Employee.DeptId=Dept.Id

Besides readability and shorter request lengths , what is the advantage of using aliases? When I consulted with our database expert, he says that the query can break down if there are times there are no aliases ... that I do not understand completely ... I would appreciate if someone would share their thoughts about which best practices to follow ... Thank you very much.

+5
source share
6 answers
  • , " " " ALIAS" .

    , , ; . .

    ANY , .

  • ( ), .

  • SQL , 100% .

    , , 1- , HARDER / .

    SQL 2 , / 10-15 , , "e", .

    2

    • - , .

    • - , - - . . "EmployeeTableIndexedByUIDSourcedFromHR" "Employee", "E"

  • , , , :

    Select Employee.Id,Dept.DeptName from Employee join Dept on Employee.DeptId=Dept.Id

SELECT  Employee.Id
       ,Dept.DeptName
FROM    Employee
JOIN    Dept
ON      Employee.DeptId=Dept.Id
+11

, .

, , .

+4

, , , . , t1, t2 ..

+3

- ; , .

... - , .

+1
  • .
0

In most cases, I prefer to use the full table names. I usually use an alias name for tables if an internal join between two tables in separate databases is required to make it more readable.

Select  Employee.Name, sales.Amount
From    Employee
        Inner Join SalesDB.dbo.Sales as Sales On Employee.ID = Sales.EmployeeID

However, I would recommend using aliases for your fields to prevent the changes needed to call applications down.

Select Employees.Name as [Name]
From   Employees
0
source

All Articles