當前位置

首頁 > 商務英語 > 計算機英語 > 資料庫中using的用法

資料庫中using的用法

推薦人: 來源: 閱讀: 1.42W 次

資料庫中using的用法的用法你知道嗎?下面小編就跟你們詳細介紹下資料庫中using的用法的用法,希望對你們有用。

padding-bottom: 75%;">資料庫中using的用法

  資料庫中using的用法的用法如下:

使用using關鍵字對連線進行簡化

在SQL/92標準可以使用USING子句對連線條件進行簡化,但是隻有在查詢滿足以下兩個條件時才能給使用USING進行簡化:

1、查詢必須是等連線的

2、等連線中的列必須是同名

如:商品表goods表和商品型別表category表中goods的外來鍵和category的主鍵相同:categoryid而且是等連線,這裡可以使用using

[sql]

select goodsname,categoryname

from goods inner join category

using(categoryid)

在使用using是需要注意以下幾個問題

1、在select子句中只能指定該列名,不能使用表名或別名

2、在using子句中也只能單獨使用列名

對於多與兩個表的連線,先看這個例子

[sql]

select tName,Name,uct_name ,uct_types_name

from customers c,purchase pr,products p,product_types pt

where omer_id=omer_id

and ucts_id = ucts_id

and uct_types_id=uct_types_id;

使用using對上面的sql語句進行重寫

[sql]

select t_name,_name,ucts_name as product,uct_types_name as typesname

from customers c inner join purchases pr

using(customers_id)

inner join products p

using(products_id)

inner join product_types pt

using(product_types_id);