microsoft / DacFx

DacFx, SqlPackage, and other SQL development libraries enable declarative database development and database portability across SQL versions and environments. Share feedback here on dacpacs, bacpacs, and SQL projects.
https://aka.ms/sqlpackage-ref
MIT License
347 stars 20 forks source link

DacFx does not indicate existing problem in query if # or @ involved in statement #389

Open IVNSTN opened 9 months ago

IVNSTN commented 9 months ago

SQL71501 does not work if a statement includes temp table or table variable reference.

Steps to Reproduce:

  1. Use script below to create new sqlproj
  2. See warning SQL71501 unresolved reference to column on this SELECT t.missing_col in SP which is expected
  3. Replace dbo.another_table in the select statement with #another_table or @another_table
  4. The warning disappears
  5. Change it back to dbo.another_table - the warning is back

It looks like a bug or feature limitation. But the statement is so trivial and column is qualified with table alias. It'd be great if the missing column reference warning worked even if # or @ involved at least in cases like described one where column belonging seems to be identifiable.

CREATE TABLE dbo.my_table (id INT);
GO
CREATE TABLE dbo.another_table (id INT);
GO
CREATE PROC dbo.my_proc
AS
BEGIN
    SET NOCOUNT ON;

    CREATE TABLE #another_table (id INT);

    DECLARE @another_table TABLE (id INT);

    SELECT t.missing_col
    FROM dbo.my_table t
    INNER JOIN dbo.another_table a
    ON a.id = t.id
END;
GO

image

# and @ are underlined on screenshot because they are unused. These hints are not related to the issue.

Did this occur in prior versions? If not - which version(s) did it work in?

(DacFx/SqlPackage/SSMS/Azure Data Studio)

namangupta211 commented 9 months ago

Hi, thanks for reaching out to us. One question, are you also not able to deploy the project, or it is just the warning?

IVNSTN commented 9 months ago

Sorry for misunderstanding

Why doesn't DacFx detect missing column reference if temp table or table variable used in query? I think it should detect this broken reference.