自动将数据从表插入到另一个表 [英] Insert Data from table to another automatically

查看:58
本文介绍了自动将数据从表插入到另一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正在创建基于MS SQL Server DB的vb.net应用程序,在我的数据库中我有2个不同的表
存储 POS

I'm creating and vb.net app which based on MS SQL Server DB and in my DB i have 2 different tables Storage and POS

存储 POS 有2列  代码
项目我需要

Storage and POS have 2 Columns Code and Item which i need

当我在<\\ n>中添加新行时,我需要的是什么strong>存储自动新行添加到
PO S 和列(代码  和  项目)价值
存储添加到 POS ,并使这些列保持最新。

what i need is when i add new row in Storage automatically a new row add to POS and the columns (Code and Item) Value add from Storage to POS and also make these columns up to date.

我尝试了计算列,但我做了一些研究,发现无法通过计算列函数插入和读取另一个表中的数据。

i tried the computed columns but i done some research and found that is not possible to insert and read data from another table by computed columns function.

那么有什么想法吗?

推荐答案

我不确定我是否正确理解了这个问题,但是此触发器应将表Storage中的所有新行复制到表POS。

I'm not sure I understand the question correctly, but this trigger should copy all new rows in table Storage to the table POS.

CREATE TRIGGER storage_insert_tri 
   ON  Storage 
   AFTER INSERT
AS 
BEGIN
   INSERT POS (
            Code
           ,Item  )
   SELECT   Code
           ,Item
   FROM     inserted 
END


这篇关于自动将数据从表插入到另一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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