数据库创建视图

创建视图:
create view 数据库名 (拥有者)视图名(列名)
with encryption,schemabinding,view_metadata
as select 语句
with check option

with encryption 用于加密create view脚本
schemabinding 将视图绑定基本表结构
view_metadata 返回浏览模式
with check option强行针对视图执行所有数据,必须符合select语句中的设置

create view view_student
with encryption
as select studentname,sex,birthday from student
查看视图:
exec sp_help 数据库对象名
exec sp_helptext 视图名
exec sp_depends 数据库对象名
exec sp_help view_student
修改视图:
Alter view(数据库名)视图名(列名1,列名2)
with encryption,schemabinding,view_metadate
AS select 语句
with check option
视图改名:
sp_rename 旧名,新名
sp_rename girl_view,boy_view
删除视图:
drop view 视图名
drop view girl_view
视图查询:
select * from 视图名
select * from girl_view where studentid=’01‘
添加记录:
insert into student (studentid,studentname,course)valuse(’01‘,’Mary‘,’26‘)
修改视图:
update girl_view set studentname='哈哈'
where studentid=’102‘
删除视图:
delete from 视图名 where studentid=’01‘
delete from v_s where studentid=’01‘

你可能感兴趣的:(SQL)