当前位置:网站首页>SQL Server view
SQL Server view
2022-06-26 05:57:00 【weixin_ forty-seven million two hundred and fifty-four thousand】
Writing time :2022 year 5 month 26 Japan
SQL Server View
Views are named queries stored in the database directory , Allow clients to reference it later . A view graph can contain columns from multiple tables using joins , You can also include only a subset of the columns of a single table . This makes views useful for abstracting or hiding complex queries .
Views have the following advantages :
Security
You can restrict users' direct access to tables , And allow them to access a subset of the data through the view . for example , You can allow users to access customer names through views , Telephone , E-mail , But restrict their access to bank accounts and other sensitive information .
Simple
A relational database can have many tables with complex relationships , for example , One to one and one to many make navigation difficult . however , You can use a set of views to simplify complex queries with joins and conditions .
Uniformity
Sometimes , You need to write complex formulas or logic in each query . To make it consistent , You can hide the complex query logic and calculations in the view . After defining the view , You can reference logic from views , Instead of rewriting it in a separate query .
SQL Server Create view :
SQL Server Create a new view : Use create view sentence :
create view [or alter] schema_name.view_name [(column_list)] as select_statement;
In the above grammar :
stay create view Keyword to specify the name of the view .schema_name Is the name of the schema to which the view belongs . Specify definition as Keyword after the view select sentence (select_statement).select Statement can reference one or more tables . If the column list of the view is not explicitly specified ,SQL Server Will use from select Statement .、
If you want to redefine the view , for example , Add more columns to it or remove some from it , Can be in create view Use after keyword or alter keyword .
Create a simple view example :
The following statement is based on orders,order_time and products Table creation name is daily_sales The view of :
create view sales.daily_sales as select
year(order_date )as y,
month(order_date ) as m,
day(order_date ) as d,
p.product_id,
product_name,
quantity * i.list_price as sales
from
sales.order_id as o
inner join sales.order_items as i
on o.order_id = i.order_id
inner join production.products as p
on p.product_id = i.product_id;
establish daily_sales After view , You can use simple select Statement to query data against the underlying table on the view :
select
*
from
sales.daily_sales
order by
y, m , d, product_name;
SQL Server Rename view
Before renaming the view , It must be noted that all view dependent objects can fail . These objects include stored procedures , User defined functions , trigger , Inquire about , Other views and client applications . therefore , After renaming the view , You must ensure that all objects to which the old name of the view is applied use the new name .
Use SSMS Rename view
To rename the name of the view , Follow these steps :
First , In object Explorer (Server Server Management Studio) in , an “ database ”, Select the database name that contains the view you want to rename , And then unfold “ View ” Folder . secondly , Right click the view you want to rename , And then choose “ rename ”
Use SQL Rename view
If you want to rename the view programmatically , have access to sp_rename stored procedure :
exec sp_rename
@objname = ‘sales.product_catalog’,
@newname =’sales.product_list’;
边栏推荐
- 冒泡排序(Bubble Sort)
- Redis底层数据结构
- Detailed explanation of serial port communication principle 232, 422, 485
- Redis underlying data structure
- Combined mode, transparent mode and secure mode
- Soft power and hard power in program development
- Source code of findcontrol
- Win socket programming (Mengxin initial battle)
- E-commerce seeks growth breakthrough with the help of small program technology
- Test depends on abstraction and does not depend on concrete
猜你喜欢

Pytorch (network model)

C generic speed

Factory method pattern, abstract factory pattern

423-二叉树(110. 平衡二叉树、257. 二叉树的所有路径、100. 相同的树、404. 左叶子之和)

Implementation of third-party wechat authorized login for applet

【群内问题学期汇总】初学者的部分参考问题

Unicloud cloud development obtains applet user openid

Selective Search for Object Recognition 论文笔记【图片目标分割】

电商借助小程序技术发力寻找增长突破口

小程序如何关联微信小程序二维码,实现二码聚合
随机推荐
Test depends on abstraction and does not depend on concrete
Kolla ansible deploy openstack Yoga version
bingc(继承)
Ribbon load balancing service call
Redis底层数据结构
Last flight
Yamaha robot splits visual strings
Ribbon负载均衡服务调用
MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications
The model defined (modified) in pytoch loads some required pre training model parameters and freezes them
one billion two hundred and twelve million three hundred and twelve thousand three hundred and twenty-one
Redis多线程与ACL
Definition of Halcon hand eye calibration
SQL Server 函数
重载和重写
5 minutes to learn regular expressions
卷妹带你学jdbc---2天冲刺Day2
Thinking about bad money expelling good money
Prototype mode, Baa Baa
Consul service registration and discovery