sql server - How can I use SQL to populate a child table with a value from the parent? -


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) ); 

i have 2 tables. problem table has title field populated.

how can populate title field of question table title of problem table ?

you can use command:

update q set q.[title] = p.[title]  question q  inner join problem p on p.[problemid] = q.[problemid] 

however not practice store duplicate data.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -