• Hugo Kornelis (10/30/2015)


    I like the question. Good reminder of the intricacies of working with views.

    There is a small mistake in the explanation, though. Changing data types will not cause conversion errors in the select statement. Repro (and watch the column name!):

    CREATE TABLE dbo.t1

    (DateCol date NOT NULL);

    INSERT INTO dbo.t1 VALUES (CURRENT_TIMESTAMP);

    GO

    CREATE VIEW dbo.v1

    AS SELECT * FROM dbo.t1;

    GO

    SELECT * FROM dbo.v1;

    DROP TABLE dbo.t1;

    CREATE TABLE dbo.t1 (CharCol varchar(20));

    INSERT INTO dbo.t1 VALUES ('I am not a datetime');

    SELECT *

    FROM dbo.v1;

    DROP VIEW dbo.v1;

    DROP TABLE dbo.t1;

    1) for the creator of this QOD : thanks for it as I have not given the good answer in an interview 6 years ago ( but the interviewer was not surprised as she got only 10% of good answer ... )

    2) for Hugo : thanks for your explanation which confirms the explanation given by this interviewer...