0
SET ANSI_NULLS ON
 GO

SET QUOTED_IDENTIFIER ON
 GO


ALTER VIEW [dbo].[pais2k1view]
AS
SELECT DISTINCT 
                  RTRIM(dbo.Gen_info.last) AS LastName, RTRIM(dbo.Gen_info.first) AS         Firstname, RTRIM(dbo.Gen_info.middle) AS Middlename, RTRIM(dbo.Gen_info.rank) AS rank, 
                  RTRIM(dbo.Gen_info.badge_no) AS badge_no, RTRIM(dbo.Gen_info.tin) AS TIN, CONVERT(char(10), dbo.Gen_info.birthdate, 110) AS birthdate, dbo.Gen_info.hair, 
                  dbo.Gen_info.eyes, RTRIM(dbo.Gen_info.blood) AS Blood, dbo.Gen_info.height, dbo.Gen_info.weight, dbo.Gen_info.marks, dbo.dependent.name, 
                  dbo.dependent.address, dbo.dependent.phone_no, dbo.dependent.dep_contact, dbo.dependent.dep_phone, dbo.Gen_info.acct_no, dbo.Gen_info.unit AS RDO_Code, 
                  dbo.Gen_info.fstatus, dbo.dependent.tag1, RTRIM(dbo.Gen_info.first) + ' ' + RTRIM(dbo.Gen_info.middle) + ' ' + RTRIM(dbo.Gen_info.last) AS Fullname, 
                  RTRIM(dbo.Gen_info.last) + RTRIM(dbo.Gen_info.first) AS Photolink, dbo.Unit.abbvr AS unit
FROM         dbo.Gen_info WITH (NOLOCK) LEFT OUTER JOIN
                  dbo.dependent WITH (NOLOCK) ON dbo.Gen_info.link = dbo.dependent.link LEFT OUTER JOIN
                  dbo.Unit WITH (NOLOCK) ON dbo.Gen_info.unit = dbo.Unit.unit
WHERE     (dbo.dependent.fstatus = 0) AND (dbo.dependent.tag1 = 1) AND (dbo.Gen_info.fstatus = 0)

我正在使用 sql management studio,这是我的更改视图,如何在此行中添加刷新命令,以便视图始终反映最新的记录

4

2 回答 2

1

你不必那样做。视图不是表,它们是预定义的查询。

当您从视图中选择时,SQL Server 会在此时执行视图的查询。

您可以通过创建视图、从中进行选择、然后将行添加到基表并再次从视图中进行选择来测试这一点。

于 2012-07-24T02:48:26.480 回答
0

如果您对基础表进行更改,则需要刷新视图以查看反映的更改,但我很确定您不能在 alter 语句中这样做。

sp_refreshview [dbo].[pais2k1view]

然后,您可以在对数据库进行更改时手动运行它,也可以将其包含在脚本中,您必须在调用视图查询之前将其自动化。

于 2012-07-24T03:01:29.340 回答