0

早上好,我有以下查询,它创建了一个临时表,我想要的是这个表是永久的,每当其他表被更新时,这个表就会自动更新,我认为有一种简单的方法可以做到这个,但我刚刚忘记了。

查询链接 3 个表

Select S.[Silks_Skey], MC.[MajorColour_Skey] 
from [dbo].[Silks] S 
inner join [dbo].[SubColour] SC on CHARINDEX(SC.[SubColour],S.[SilksName]) <> 0
inner join [dbo].[MajorColour] MC on SC.[MajorColour] = MC.[MajorColour]

UNION ALL

Select S.[Silks_Skey], MC.[MajorColour_Skey] 
from [dbo].[Silks] S 
inner join [dbo].[MajorColour] MC on CHARINDEX(MC.[MajorColour],S.[SilksName]) <> 0

ORDER BY S.[Silks_Skey]

将链接表变成永久表

Silks_Skey  MajorColour_Skey
1   7
1   8
2   2
2   8
2   9
3   4
3   5
4

2 回答 2

0

何关于为此使用视图。正如您所说,您希望在更新表时更新此查询结果。使其成为视图。

于 2013-05-02T09:23:32.627 回答
0
CREATE VIEW [silkColours]
AS
Select S.[Silks_Skey], MC.[MajorColour_Skey] 
from [dbo].[Silks] S 
inner join [dbo].[SubColour] SC on CHARINDEX(SC.[SubColour],S.[SilksName]) <> 0
inner join [dbo].[MajorColour] MC on SC.[MajorColour] = MC.[MajorColour]

UNION ALL

Select S.[Silks_Skey], MC.[MajorColour_Skey] 
from [dbo].[Silks] S 
inner join [dbo].[MajorColour] MC on CHARINDEX(MC.[MajorColour],S.[SilksName]) <> 0

ORDER BY S.[Silks_Skey]
于 2013-05-02T09:24:02.253 回答