1

I have two tables: WordForm and WordDefinition:

CREATE TABLE [dbo].[WordForm] (
    [WordFormId]    VARCHAR (20)  NOT NULL,
    [WordId]     VARCHAR (20)  NOT NULL,
    [Primary]    BIT           DEFAULT ((0)) NOT NULL,
    [PosId]      INT           NOT NULL,
    -- I want to move text data from this column into 
    -- the WordDefinition table column called Definition
    -- and then I will remove the column from here later.
    [Definition] VARCHAR (MAX) NULL, 
    [Sample]     VARCHAR (MAX) NULL,
    [Synonym]    VARCHAR (100) NULL,
    PRIMARY KEY CLUSTERED ([WordFormId] ASC),
    CONSTRAINT [FK_WordFormPos] FOREIGN KEY ([PosId]) REFERENCES [dbo].[Pos] ([PosId]),
    CONSTRAINT [FK_WordFormWord] FOREIGN KEY ([WordId]) REFERENCES [dbo].[Word] ([WordId])
);



CREATE TABLE [dbo].[WordDefinition]
(
    [WordDefinitionId] INT IDENTITY (1, 1) NOT NULL,
    [WordFormId]    VARCHAR (20)  NOT NULL,
    [Definition]  VARCHAR (MAX) NOT NULL
    CONSTRAINT [PK_WordDefinition] PRIMARY KEY CLUSTERED ([WordDefinitionId] ASC),
)

Initially the WordForm table was created to hold single definitions but now I realize there can be more definitions for each WordForm.

To implement this I added the WordDefinition table. One WordForm row to Many WordDefinition rows.

But now what I need to do is to go through the WordForm table and add an entry with the original definition (from WordForm) and copy this into the WordDefinition table for each row in WordForm.

Is this something I could do only with SQL or would I need to use a cursor. Any help and advice on how to do this would be much appreciated.

Alan2
  • 23,493
  • 79
  • 256
  • 450

1 Answers1

1

I think you can just use 1 query INSERT INTO SELECT to do this, something like this:

INSERT INTO [dbo].[WordDefinition]
SELECT [WordFormId], [Definition] 
FROM [dbo].[WordForm]

After that you can delete the old column Definition from WordForm.

King King
  • 61,710
  • 16
  • 105
  • 130