Sql Server数据库视图的创建、修改


 1 if OBJECT_ID('Sales.USACusts') is not null
 2     drop view Sales.USACusts;
 3 go
 4 
 5 create view Sales.USACusts
 6 as
 7 select custid,companyname,contactname,contacttitle,address,city,region,postalcode,country,phone,fax
 8 from Sales.Customers
 9 where country=N'USA';
10 go

在数据库的Sales架构中创建一个名为USACusts的视图,代表所有来自美国的用户。

注意,就像使用派生表和CTE一样,要替代前面代码中所显示的内嵌列别名,可以使用外部列别名方式,即在视图名称后面紧跟的圆括号内制定目标列名称。

 

修改视图

1 alter view Sales.USACusts
2 as
3 select custid,companyname,contactname,contacttitle,address,city,region,postalcode,country,phone,fax
4 from Sales.Customers
5 where country=N'USA';
6 go

 

 

-------------------------摘自《SQL Server 2012 T-SQL基础教程》【美】Itzik Ben-Gan 著


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM