如何将来自一列的数据插入到另一列的表中

时间:2022-01-23 04:47:35

I have two tables LESSON & SPORT.

我有两张课桌。

LESSONNO | SPORTNO | INSTRUCTORNO | DATE | PRICE |

第2课|体育节目|教学节目|日期|价格|

SPORTNO | SPORT NAME | SPORTDESCRIPTION |

体育名称

I need to add column SPORTNAME to the lesson table, and for its data to match the SPORTNO in lesson table as it does in sport table.

我需要向课程表中添加列SPORTNAME,并将其数据与课程表中的SPORTNO匹配,就像在运动表中那样。

Thanks in advance!

提前谢谢!

2 个解决方案

#1


1  

Does this work for you:

这对你有用吗:

ALTER TABLE LESSON ADD SPORTNAME VARCHAR(30); // or whatever type it is
UPDATE LESSON l JOIN SPORT s USING(SPORTNO) SET l.SPORTNAME = s.SPORTNAME;

?

吗?

#2


1  

This worked for me in SQL Server

这在SQL Server中对我很有用

 ALTER TABLE LESSON ADD SPORTNAME VARCHAR(50)

  UPDATE LESSON
  SET SPORTNAME = S.SPORTNAME
  FROM dbo.LESSON AS L
  INNER JOIN dbo.SPORT AS S
  ON L.SPORTNO = S.SPORTNO

Hope it helps!

希望它可以帮助!

#1


1  

Does this work for you:

这对你有用吗:

ALTER TABLE LESSON ADD SPORTNAME VARCHAR(30); // or whatever type it is
UPDATE LESSON l JOIN SPORT s USING(SPORTNO) SET l.SPORTNAME = s.SPORTNAME;

?

吗?

#2


1  

This worked for me in SQL Server

这在SQL Server中对我很有用

 ALTER TABLE LESSON ADD SPORTNAME VARCHAR(50)

  UPDATE LESSON
  SET SPORTNAME = S.SPORTNAME
  FROM dbo.LESSON AS L
  INNER JOIN dbo.SPORT AS S
  ON L.SPORTNO = S.SPORTNO

Hope it helps!

希望它可以帮助!