• Don Avery (1/3/2011)


    Actually, I'm right - this query will return 0 rows for both SELECT statements as it will never run - you cannot insert into a table with and Identity PK without specifying the column names on the INSERT query.

    Actually, you are wrong. The script will run. You don't need to specify column names when inserting into a table with an IDENTITY column.

    After reading your reply, I started to doubt, so I copied the script, pasted it in SSMS, changed it to work for SQL Server 2005 - I replaced the single INSERT with three INSERT statements:

    INSERT INTO @student

    VALUES( 'Hardy', 100);

    INSERT INTO @student

    VALUES ('Rocky', 98);

    INSERT INTO @student

    VALUES ('Panky', 99);

    I then hit the F5 button to execute, and I got the expected results.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/