Quote:
|
Originally Posted by v3nom
This would effectively mean i am running the query twice on the same table
|
Not at all: a "SELECT from FINAL TABLE" will query the rows being added to the table
while doing the INSERT, so no double work at all.
By the way: this "select from insert" syntax also gives you the possibility to find out which were the default values and/or identity column values being inserted.
Example: suppose table1 has columns (ID, NAME), where ID is the PK, an identity column.
Code:
SELECT id FROM FINAL TABLE (INSERT INTO table1(name) VALUES ('Peter') )
would return me the PK of the row that I just inserted; very difficult to find out which it was otherwise!
This clearly does *not* query the base table twice: the SELECT just interrogates the single row inserted into table1,
just after the row to be inserted has been fully built up.