CREATE TABLE [dbo].[Problem] (
[ProblemId] INT IDENTITY (1, 1) NOT NULL,
[Title] NVARCHAR (100) NOT NULL,
CONSTRAINT [PK_Problem] PRIMARY KEY CLUSTERED ([ProblemId] ASC)
);
CREATE TABLE [dbo].[Question] (
[QuestionId] INT IDENTITY (1, 1) NOT NULL,
[ProblemId] INT NOT NULL,
[Title] NVARCHAR (100) NULL,
CONSTRAINT [PK_Question] PRIMARY KEY CLUSTERED ([QuestionId] ASC)
);
我有两张桌子。问题表已填充标题字段。
如何使用问题表的标题填充问题表的标题字段?
答案 0 :(得分:1)
您可以使用此命令:
UPDATE q SET q.[Title] = p.[Title]
FROM Question q
INNER JOIN Problem p ON p.[ProblemId] = q.[ProblemId]
但是,存储重复数据通常不是一个好习惯。