8.4. A Note on Flaws in a Common Vendor Extension

While I do not like to spend much time discussing nonstandard SQLlike languages, the T-SQL language from Sybase and Microsoft has a horrible flaw in it that users need to be warned about. They have a proprietary syntax that allows a FROM clause in the UPDATE statement. If the base table being updated is represented more than once in the FROM clause, then its rows can be operated on multiple times, in a total violation of relational principles. The correct answer is that when you try to put more than one value into a column, you get a cardinality violation and the UPDATE fails. Here is a quick example:

CREATE TABLE T1 (x INTEGER NOT NULL); INSERT INTO T1 VALUES (1), (2), (3), (4); CREATE TABLE ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.