将数据插入两个表.. [英] Insert Data Into two tables..
本文介绍了将数据插入两个表..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
先生在我的应用程序中我有2个表,主表和详细信息表..文本框值插入主表和网格视图数据插入详细信息表..
使用存储过程如何在单个过程中插入两个数据。帮助先生
Sir in my application i have 2 tables , Master table & Detail table.. Text box values are insert into master table & grid view data insert into Detail table..
Using store procedure how to insert both data in single procedure . help sir
推荐答案
你可以编写一个程序
You can write a single procedure
USE [YourDatabase]
GO
/****** Object: StoredProcedure [dbo].[SP_Fr_FileUpDate] Script Date: 02/10/2014 09:00:44 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create procedure [dbo].[SP_Fr_FileUpDate]
@param1 varchar(MAX),
@param2 int,
@param3 Date
as
Begin
Insert Query
Insert Query
END
end
Crate a SP
Crate an SP
ECLARE @NewID INT
INSERT INTO Table1(A,B,C......) VALUES(a,b,c, .....)
SELECT @NewID = SCOPE_IDENTITY()
INSERT INTO Table2(A,B,C...) VALUES(@NewID, B,..........)
begin transaction
insert query for first table
insert query for second table
Rollback transaction
这篇关于将数据插入两个表..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文