将列值写入2个表 [英] write a column value in to 2 tables
本文介绍了将列值写入2个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我正在编写一个程序,我有2个表,其中一个列名为User ID,该列是两个表中的主键.如果另一个列被填充并且有种子和增量,则填充其中一个表中的用户ID.当我编写查询以在该表中添加数据时,我希望用户ID通过我在第一个表中具有的相同值添加到其他表中.
hi all,
I am writing a program and i have 2 table with a column named User id that this column is primary key in both of tables.and user id in one of tables is fill if other column is filled and it have a seed and an increment.when i write a query for adding data in that table i want to user id to be add to other table by the same value that i have in first table
what i must do?
推荐答案
您必须先在用户表中插入,然后再询问最新的身份.
将该值存储在变量中,然后在第二个插入中使用它.
You have to insert first in the user table and after that ask the newest identity.
Store that value in a variable and use it in your second insert.
declare @userID int
set @userID = Scope_Identity()
这篇关于将列值写入2个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文