SELECT 'Test1' WHERE EXISTS (SELECT 1/0)
SELECT 'Test2' WHERE EXISTS (SELECT *)
Those 2 statements won't raise an Error in SQL SERVER!
Te results will be:
Test1
Test2
Of course that SELECT 1/0 or SELECT * will raise an Error.
In SQL SERVER the FROM clause is optional.
This is why SELECT 1 , SELECT @P and SELECT @P=5 are permitted.
In other database systems (Like Oracle), SELECT statement without FROM clause is not permitted, and there is a dummy table "DUAL" with one row that is used to do such SELECT statements:
SELECT 1 FROM dual , SELECT @v FROM dual.
Another thing is that in EXISTS clause doesn't matter in terms of the syntax or result of the query.
Those 2 facts (SELECT without FROM is allowed and EXISTS doesn't matter in terms of the syntax)
explains the behavior of the 2 statements above.
No comments:
Post a Comment