Database VIEW does not reflect the data in the underying TABLE

前端 未结 6 1666
情话喂你
情话喂你 2021-01-04 12:40

Input:

The customer claims that the application (.NET) when querying for some data returns data different from when the customer looks into the data table directly

6条回答
  •  误落风尘
    2021-01-04 13:18

    A few possibilities:

    • Your .NET application may not be pointing to where you or they think it is pointing. For example, it's pointed to a test server by mistake

    • If the view has an index on a float or numeric value, the value may appear different from the underlying query due to rounding

    • The ANSI_NULLS setting is specific to the view when it was created. If it's different from the setting during the select(s) on the underlying tables it could cause discrepancies for certain kinds of queries

    • The underlying table structures have changed and the view hasn't been refreshed (especially a problem if it uses "SELECT *")

    I'll edit this post if I think of any others.

    EDIT: Here's an example of how the ANSI_NULLS setting can throw off your results:

    SET ANSI_NULLS ON
    
    DECLARE
         @i     INT,
         @j     INT
    
    SET @i = NULL
    SET @j = 1
    
    SELECT
         CASE WHEN @i <> @j THEN 'Not Equal' ELSE 'Equal' END
    
    SET ANSI_NULLS OFF
    
    SELECT
         CASE WHEN @i <> @j THEN 'Not Equal' ELSE 'Equal' END
    

    The results which you should receive are:

    Equal
    
    Not Equal
    

提交回复
热议问题