sql根据表1ID修改表2品种的数据改怎样写?

sql根据表1ID修改表2品种的数据改怎样写?

多谢各位帮忙指点指点。

img

img


SELECT TOP (1000) [ID] ,[text] FROM [aaaa].[dbo].[Table_1];

update B set B.text = A.text from [aaaa].[dbo].[Table_1] A, [aaaa].[dbo].[Table_2] B where B.ID = (select ID from [aaaa].[dbo].[Table_1] where text='苹果');

SELECT TOP (1000) [ID] ,[text] FROM [aaaa].[dbo].[Table_2];

那试一下这种:
update 表2 set 品种 = (select 种类 from 表1 where 表1.id = 表2.id)


update2
   set 品种 = '苹果'
 where id = (select id from1 where 种类 = '苹果')

update 表1 inner join 表2 on 表1.ID= 表2.ID set 表2.品种= 表1.种类



```sql

create table A
(
    Tid int primary key identity,
    Tname nvarchar(20)
)

insert into A values ('苹果'),('香蕉'),('柠檬'),('柑子'),('葡萄')

create table B
(
    Id int primary key identity,
    Name nvarchar(20),
    Tid int foreign key references A(Tid)
)

insert into B values 
('红色',1),
('红色',2),
('红色',3),
('红色',4),
('红色',5)

update B set Name='蛇果' where Tid=
(
    select Tid from A where Tname='苹果'
)

img

```

img

我没创建数据库你自己创建一下 就是一个嵌套修改