sql别名无效_SQL别名

sql别名无效

Sql Alias

Sql Alias

SQL别名


There are cases when the column name or the table name that is existing in the database is not so human readable. We can use SQL ALIAS feature to assign a new name to the table or columns in our query.
在某些情况下,数据库中存在的列名或表名不是很容易理解。 我们可以使用SQL ALIAS功能为查询中的表或列分配新名称。

SQL ALIAS is used for temporary naming of table or column of a table for making it more readable. The renaming is temporary in nature and does not affect the real name of the table or the column of the table.

SQL ALIAS用于​​临时命名表或表的列,以使其更具可读性。 重命名本质上是临时的,不会影响表或表的列的真实名称。

The lifetime of the SQL ALIAS is till the duration of the query where SQL ALIAS is defined.

SQL ALIAS的生存期一直到定义SQL ALIAS的查询持续时间为止。

SQL ALIAS is more useful where multiple tables are involved like in case of JOINS.

SQL ALIAS在涉及多个表(如JOINS的情况)时更有用。

We will discuss the usage of SQL ALIAS for table and column name of the table in detail in the below-mentioned sections.

我们将在以下各节中详细讨论表的表名和列名SQL ALIAS用法。

表名称SQL别名 (SQL Alias For Table Name)

Syntax:

语法

SELECT column_name(s) FROM table_name AS alias_name;

In the syntax above the alias_name is the name that will be temporarily assigned for the table_name.

在上面的语法中,alias_name是将临时分配给table_name的名称。

Let’s try an understand in detail about aliasing a table name using the below-mentioned example.

让我们尝试使用下面提到的示例来详细了解有关别名表名称的信息。

We will consider the below mentioned Product and Supplier table for example purpose.

我们将以下面提到的“产品和供应商”表为例。

Product Table:

产品表:

ProductIDProductNameSupplierID
1Cookies2
2Jam2
3Butter1
4Bread3
5Cake1
产品编号 产品名称 供应商编号
1个 饼干 2
2 果酱 2
3 牛油 1个
4 面包 3
5 蛋糕 1个

Supplier Table:

供应商表:

SupplierIDSupplierName
1ABC
Company
2ACD Industries
3XYZ Pvt
Ltd
供应商编号 供应商名称
1个 美国广播公司
公司
2 ACD产业
3 XYZ列印
有限公司

Scenario: Get the name of all the products and their supplier name along with the productid.

场景 :获取所有产品的名称及其供应商名称以及productid。

SQL Select Query:

SQL选择查询:

SELECT p.ProductID, p.ProductName, s.SupplierName FROM Product AS p, Supplier AS s WHERE p.SupplierID = s.SupplierID;
ProductIDProductNameSupplierName
1CookiesACD
Industries
2JamACD Industries
3ButterABC Company
4BreadXYZ Pvt Ltd
5CakeABC Company
产品编号 产品名称 供应商名称
1个 饼干 ACD
产业领域
2 果酱 ACD产业
3 牛油 ABC公司
4 面包 XYZ Pvt Ltd
5 蛋糕 ABC公司

In the output above SQL ALIAS, is used for aliasing the table name, making it easy to differentiate the two SupplierID columns of Product and Supplier table.

在SQL ALIAS上方的输出中,使用别名表名称,可以轻松区分Product和Supplier表的两个SupplierID列。

列名称SQL别名 (SQL Alias For Column Name)

Syntax:

句法:

SELECT column_name AS alias_name FROM table_name;

In the syntax above the alias_name is the name that will be temporarily assigned for the column_name.

在上面的语法中,alias_name是将为column_name临时分配的名称。

Let’s try an understand in detail about aliasing a column name using the below-mentioned example.

让我们尝试使用下面提到的示例来详细了解有关别名别名的信息。

Scenario: Get the name of all the products and their supplier name along with the productid. The ProductName column should be displayed as Product and SupplierName column should be displayed as Supplier.

场景 :获取所有产品的名称及其供应商名称以及productid。 ProductName列应显示为Product,而SupplierName列应显示为Supplier。

Query:

查询:

SELECT p.ProductID, p.ProductName AS Product, s.SupplierName AS Supplier FROM Product AS p, Supplier AS s WHERE p.SupplierID = s.SupplierID;
ProductIDProductSupplier
1CookiesACD Industries
2JamACD Industries
3ButterABC Company
4BreadXYZ Pvt Ltd
5CakeABC Company
产品编号 产品 供应商
1个 饼干 ACD产业
2 果酱 ACD产业
3 牛油 ABC公司
4 面包 XYZ Pvt Ltd
5 蛋糕 ABC公司

In the example above we have seen the usage of alias for table and column both in a single query.

在上面的示例中,我们已经在单个查询中看到了表和列别名的用法。

翻译自: https://www.journaldev.com/24784/sql-alias

sql别名无效

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值