Alt sorgular içinde sütun adlarını nitelerken olduğu
Aşağıdaki örnekte, CustomerID sütun dış sorgunun where yan tümce tümce tümcesinde dış sorgunun from yan tümce tümce tümce, tablo adını yazarak tam örtülü olarak Sales.Store.Başvuru CustomerID alt sorgu seçme listesinde tarafından alt sorgunun from yan tümce tümce tümce, yan tümce tümcei nitelikli, bunun Sales.Customer tablo.
USE AdventureWorks2008R2;
GO
SELECT Name
FROM Sales.Store
WHERE BusinessEntityID NOT IN
(SELECT CustomerID
FROM Sales.Customer
WHERE TerritoryID = 5)
Genel bir deyim sütun adı tarafından dolaylı olarak nitelenir kuraldır tablo aynı düzeyde from yan tümce tümce tümcesinde başvurulan.Bir sütunu yoksa, tablo , bir alt sorgunun from yan tümce tümce tümcesinde başvurulan, onu dolaylı olarak tarafından yetkili tablo dış sorgunun from yan tümce tümce tümcesinde başvurulan.
Sorguyu belirtilen bu örtülü varsayımlar ile nasıl göründüğünü aşağıdadır:
USE AdventureWorks2008R2;
GO
SELECT Name
FROM Sales.Store
WHERE Sales.Store.BusinessEntityID NOT IN
(SELECT Sales.Customer.CustomerID
FROM Sales.Customer
WHERE TerritoryID = 5)
Hiçbir zaman tablo adı açıkça durumu yanlış olur ve her zaman açık nitelikleri ile tablo adları hakkında örtülü varsayımlar geçersiz kılmak mümkündür.
Dikkat |
---|
If a column is referenced in a subquery that does not exist in the table referenced by the subquery's FROM clause, but exists in a table referenced by the outer query's FROM clause, the query executes without error.SQL Server implicitly qualifies the column in the subquery with the table name in the outer query. |