SQL Insert into Where和loops [英] SQL Insert Into Where and loops

查看:96
本文介绍了SQL Insert into Where和loops的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想将一列数据从一个表移动到另一个表。但数据必须与ID匹配。新表与前一个表具有相同的ID,所以显然这些数据必须与新表ID匹配,



i写了一个SQL语句,我认为它会如何工作(有点伪),请有人帮我纠正我的错误或帮助我如何写它..



So, i'm wanting to move a column of data from one table to another. But the data has to match with an ID. The new table have all the same ID's as the previous table, so obviously this data must match with new table ID,

i have wrote a SQL statement how i thought it would have worked (kinda pseudo), please could someone help me correct my mistakes or help in how i should write it..

INSERT INTO Uni_Course_Info i (UCS_Title)
SELECT UCM_TITLE FROM Uni_CourseModule_OLD cm WHERE i.UCS_ID = cm.UCM_ID

推荐答案

如果表已有数据意味着您必须更新,则无法插入



试试这个



if the Table already have data means you have to Update ,you can't insert

Try this

select *From Uni_Course_Info as a inner join Uni_CourseModule_OLD as b on a.USC_id=b.UCM_ID

 update a set a.UCS_Title=b.UCM_TITLE From Uni_Course_Info as a inner join Uni_CourseModule_OLD as b on a.USC_id=b.UCM_ID



:)


:)


这篇关于SQL Insert into Where和loops的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆