将一个表的同一字段更新为另一表

编程入门 行业动态 更新时间:2024-10-24 20:11:59
本文介绍了将一个表的同一字段更新为另一表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 嗨 我有两个表,tablemain和tablesecond 在主表中,字段名rollno有20条记录. 现在我达到了tablesecond. ,表格秒也具有相同的字段名称rollno. 我需要从第一个表的卷号更新表第二的卷号. 我如何实现这一点,请帮忙!

解决方案

我无法更改约束,能否给我子查询 没有人要求您更改任何约束条件.您的设计错误,要求您对其进行更正.显然,这应该是外键候选人. 您应该修正表设计并确保主表rollno是tablesecond的外键,而不是每次都尝试更新/更正两个表中的rollno字段. 但是,如果您要将表1的滚动编号更新为表2,则首先需要在表2中获取缺少的滚动编号,然后将其插入.

选择 Rollno FROM 主表其中 rollno 不 IN (>选择 Rollno 来自 TableSecond)

无论是SP还是代码,都需要遍历这些rollno来插入和匹配两个表.

使用外键概念可以解决您的问题.确保将第一个表的rollno列用作主键.

使用AFTER UPDATE触发器/AFTRE INSERT触发器可解决此问题 有关触发器的更多详细信息,请参见 Article [ ^ ]

hi i have two table, tablemain and tablesecond In main table , the fieldname rollno have 20 record. now i made tablesecond. , table second also have same field name rollno. i need to update the rollno of table second from roll no of first table. how i achieve this please help!

解决方案

I cant change constraint,, can you give me sub query No body is asking you to change any constraint. You have a wrong design and you are being asked to correct it. This clearly should be Foreign Key candidate. Instead of trying to update/correct the rollno field in both tables everytime, you should fix the table design and make sure that main table rollno is a foreign key of tablesecond. Still, if you want to update roll no from table 1 to table 2, then first you need to get the missing rollno in table2 and then insert them.

Select Rollno FROM mainTable Where rollno NOT IN (Select Rollno from TableSecond)

Either in SP or code, you need to loop through these rollno to insert and match the two tables.

Use Foreign Key concept u''ll be able to solve your problem. make sure the rollno column of first table is made as primary key.

use AFTER UPDATE Trigger/AFTRE INSERT Trigger for this problem for more detail for trigger look this Article[^]

更多推荐

将一个表的同一字段更新为另一表

本文发布于:2023-10-27 00:13:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1531757.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!