视图

视图包含行和列,就像一个真实的表。视图中的字段就是来自一个或多个数据库中的真实的表中的字段。

我们可以向视图添加 SQL 函数、WHERE 以及 JOIN 语句,我们也可以提交数据,就像这些来自于某个单一的表。

注释:数据库的设计和结构不会受到视图中的函数、where 或 join 语句的影响。

--先判断是否存在视图,存在删除

if exists (select 1 from sysobjects where id = object_id('VDefBatchRule')

and type = 'V')

drop view VDefBatchRule

go

--建立视图

create view VDefBatchRule as

SELECT a.BatchRuleCode , a.BatchRuleName , a.SplitChar , b.BatchAttributeCode , c.BatchAttributeName , c.InPutType , c.DefaultValue

FROM TDefBatchRule a INNER JOIN TDefBatchRuleDet b ON a.BatchRuleCode = b.BatchRuleCode

INNER JOIN TDefBatchAttribute c ON b.BatchAttributeCode = c.BatchAttributeCode

go

原文地址:https://www.cnblogs.com/anyihen/p/12327667.html