1

我想将视图元信息(例如关于哪些表和列以及创建的查询等)存储到另一个映射表中,以便稍后可以重现它们。

现在我有一个这样的结构 -

CREATE TABLE [dbo].[MAPPING_VIEW]
(
    [ID] [int] NOT NULL,
    [OLD_VIEW] [varchar](40) NULL,
    [NEW_VIEW] [varchar](40) NULL,

    CONSTRAINT [PK_MAPPING_VIEW] PRIMARY KEY CLUSTERED 
    ([ID] ASC)
) 

CREATE TABLE [dbo].[MAPPING_VIEW_TBL]
(
    [ID] [int] NULL,
    [PARENT_ID] [int] NULL,
    [OLD_TBL] [varchar](40) NULL,
    [NEW_TBL] [varchar](40) NULL
) 

ALTER TABLE [dbo].[MAPPING_VIEW_TBL] WITH NOCHECK 
ADD CONSTRAINT [FK_MAPPING_VIEW_TBL_ID] 
FOREIGN KEY([PARENT_ID]) REFERENCES [dbo].[MAPPING_VIEW] ([ID])

CREATE TABLE [dbo].[MAPPING_VIEW_TBL_COL]
(
    [ID] [int] NULL,
    [PARENT_ID] [int] NULL,
    [VIEW_ID] [int] NULL,
    [OLD_COL] [varchar](40) NULL,
    [NEW_COL] [varchar](40) NULL,
    [OLD_ALIAS] [varchar](40) NULL,
    [NEW_ALIAS] [varchar](40) NULL
)

ALTER TABLE [dbo].[MAPPING_VIEW_TBL_COL] WITH NOCHECK 
ADD CONSTRAINT [FK_MAPPING_VIEW_TBL_COL_PARENT_ID] 
FOREIGN KEY([PARENT_ID]) REFERENCES [dbo].[MAPPING_TBL] ([ID])

ALTER TABLE [dbo].[MAPPING_VIEW_TBL_COL]  WITH NOCHECK 
ADD CONSTRAINT [FK_MAPPING_VIEW_TBL_COL_VIEW_ID] 
FOREIGN KEY([VIEW_ID]) REFERENCES [dbo].[MAPPING_VIEW] ([ID])

我知道,这还不够。任何建议,将不胜感激

4

0 回答 0