如何从父表列中将数据插入子表?

时间:2016-05-15 08:22:23

标签: sql-server

我有一个包含SampleSentences Sample1,Sample2,Sample3,Sample4的表 和Sample5。

CREATE TABLE [dbo].[WordForm] 
(
    [WordFormId]       VARCHAR (20)  NOT NULL,
    [WordFormIdentity] INT           IDENTITY (1, 1) NOT NULL,
    [Sample1]          VARCHAR (MAX) NULL,
    [Sample2]          VARCHAR (MAX) NULL,
    [Sample3]          VARCHAR (MAX) NULL,
    [Sample4]          VARCHAR (MAX) NULL,
    [Sample5]          VARCHAR (MAX) NULL,

    PRIMARY KEY CLUSTERED ([WordFormId] ASC))
);

我决定为这些数据添加一个新表:

CREATE TABLE [dbo].[SampleSentence] 
(
    [SampleSentenceId] INT           IDENTITY (1, 1) NOT NULL,
    [WordFormId]       VARCHAR (20)  NOT NULL,
    [Text]             VARCHAR (MAX) NOT NULL,

    CONSTRAINT [PK_SampleSentence] 
        PRIMARY KEY CLUSTERED ([SampleSentenceId] ASC),
    CONSTRAINT [FK_SampleSentenceWordForm] 
        FOREIGN KEY ([WordFormId]) REFERENCES [dbo].[WordForm] ([WordFormId])
);

有人可以建议我如何从Sample1,Sample2,Sample3,Sample4和Sample5中取出数据并将其插入到新SampleSentence表中行的文本列中吗?

1 个答案:

答案 0 :(得分:1)

你想要这个:

(index,value)