简体   繁体   中英

SQL Server equivalent of MySQL's USING

In MySQL, you can use the keyword USING in a join when you join on columns from different tables with the same name. For example, these queries yield the same result:

SELECT * FROM user INNER JOIN perm USING (uid)
SELECT * FROM user INNER JOIN perm ON user.uid = perm.uid

Is there an equivalent shortcut in SQL Server?

不,不得不使用:

SELECT * FROM user INNER JOIN perm ON user.uid = perm.uid

No, SQL Server does not support this kind of shortcut.

I would like to point out that even if it did, shortcuts like these are NOT A GOOD IDEA. I recently worked on a database where the developers thought it would be a good idea to use the *= and =* shortcuts for RIGHT JOIN and LEFT JOIN. Good idea until someone upgraded the SQL Compatibility level to 90. Then it became an extremely Bad Idea.

So, learn from us. Shortcuts are bad. A little extra typing never killed anyone.

另外,我想在select语句中添加不使用泛字符“*” - 显式指定列名。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM