创建后如何更新不同表中的列值. [英] How to update the column values in different tables, when it has created.

查看:66
本文介绍了创建后如何更新不同表中的列值.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有3个表,例如客户表",任务表"和查询表".在这里,当我更新客户信息时,这些信息将保存到客户表"并生成一个客户ID.之后,我需要插入该客户的查询详细信息(此处查询和任务详细信息类似),因此,当我更新查询详细信息时,我将在任务表"和查询表"中创建行并生成TID和EID之类的ID.在这里,我的挑战是,在客户表"中,我有一列称为最新查询",在"EnquiryTable"中,我有一列称为"TID",因此在这些行中,我需要更新id(TID从' 任务表").

在此先感谢.

Hi All,

I have 3 tables like, ''Customer Table'', ''Task Table'' and ''Enquiry Table''. Here when i update the customer info, those information is saved to ''Customer Table'' and generate a customerID. After that I need to insert the enquiry details of that customer (Here Enquiry and task details are Similar), so when I update the enquiry details, I am creating the row in ''Task Table'' and in ''Enquiry Table'' and generating the ID like TID and EID. Here my challenge is, In ''Customer Table'' I have column called "Latest Enquiry" and in ''EnquiryTable'' I have a column called "TID", so in these rows I need to update the id(TID from ''Task Table'').

Thanks in Advance.

推荐答案

假设您正在使用MS SQL Server,则可以使用
Assuming you are using MS SQL Server, you can use SCOPE_IDENTITY()[^] to capture the auto generated ID.

Here is a sample
DECLARE @CustomerID INT

--Insert Customer data
INSERT INTO Customer(Name, Email) VALUES ('Customer 1', 'xyz@xyz.com')

--Store the Auto generated ID in @CustomerID 
SELECT @CustomerID = SCOPE_IDENTITY()



现在,您可以使用"@CustomerID"变量在另一个表中插入生成的客户ID.

希望这会有所帮助.



Now you can use the "@CustomerID" variable to insert generated customer ID in another table.

Hope this helps.


Chetan,

如果要将TID表单任务表更新为客户表和查询表,则首先需要在任务表中插入行,然后将任务ID更新为查询表,最后创建客户表并在此处更新ID.

请让我知道是否需要更多帮助.
Hi Chetan,

If you want to update TID form task table into customer table and inquiry table then first you need to insert row into Task table and then update task id into inquiry table and finally create customer table and update the id here.

Please let me know if you need any more help.


这篇关于创建后如何更新不同表中的列值.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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