Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - lack of NATURAL JOIN / x JOIN y USING(field)

I've just been reading up on NATURAL JOIN / USING - SQL92 features which are (sadly?) missing from SQL Server's current repertoire.

Has anyone come from a DBMS that supported these to SQL Server (or another non-supporting DBMS) - were they as useful as they sound, or a can of worms (which also sounds possible!)?

like image 748
Will A Avatar asked Jul 18 '10 22:07

Will A


People also ask

What is the major drawback of natural join?

The common complaint about NATURAL JOIN is that since shared columns aren't explicit, after a schema change inappropriate column pairing may occur. And that may be the case in a particular development environment.

Can we use using clause with natural join?

NATURAL JOIN and USING Clause are mutually exclusive. It should not have a qualifier(table name or Alias) in the referenced columns. NATURAL JOIN uses all the columns with matching names and datatypes to join the tables. The USING Clause can be used to specify only those columns that should be used for an EQUIJOIN.

Is Natural join available in SQL Server?

MS SQL does not support natural join, neither join using (). You have to explicitly write down all your attributes used in the join.

What are the criteria needs to satisfy for natural join?

When you specify a NATURAL JOIN, the database server generates a join condition based on columns with the same name. For this to work in a natural join of base tables, there must be at least one pair of columns with the same name, with one column from each table. If there is no common column name, an error is issued.


1 Answers

I never use NATURAL JOIN because I don't like the possibility that the join could do something I don't intend just because some column name exists in both tables.

I do use the USING join syntax occasionally, but just as often it turns out that I need a more complex join condition than USING can support, so I convert it to the equivalent ON syntax after all.

like image 173
Bill Karwin Avatar answered Nov 08 '22 22:11

Bill Karwin