Home >Database >Mysql Tutorial >SQL Server 2000的视图中必须小心使用*符号_MySQL

SQL Server 2000的视图中必须小心使用*符号_MySQL

WBOY
WBOYOriginal
2016-06-01 14:00:131082browse

SQLServer2000

有些朋友看到这个标题可能会有疑问,难道在视图中使用*符号还有何要注意的地方吗?对于这个问题,我们先不必回答,先看一下例子吧。

我这里,使用的数据库是SqlServer2000自带的Northwind,这样方便大家自己私下里测试。首先,创建两个视图,视图的脚本如下:

--视图 vCustomersA

create view vCustomersA

as

select CustomerID ,CompanyName,ContactName,ContactTitle,

Address,City,Region,PostalCode,Country,Phone,Fax

from dbo.Customers

go

--视图 vCustomersB

create view vCustomersB

as

select * from vCustomersA

go

然后,使用这两个视图查询客户ID为ALFKI的资料,查询语句如下:

select * from vCustomersA where CustomerID = 'ALFKI'

select * from vCustomersB where CustomerID = 'ALFKI'

查询的结果如下:

一切正常,这个时候,需求发生了变化,我们需要改动vCustomersA,改动后的脚本如下:(为了说明问题,我们只是把CompanyName和ContactName互换一下位置)

--改动后的视图vCustomersA

alter view vCustomersA

as

select CustomerID ,ContactName,CompanyName,ContactTitle,

Address,City,Region,PostalCode,Country,Phone,Fax

from dbo.Customers

go

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn