如何从同一个存储过程将值插入到两个不同的表中?
发布于 2014-06-09 21:27:23
是的,很容易:
CREATE PROCEDURE [dbo].[InserIntoTwoTables]
@arg1 INT,
@arg2 INT,
@arg3 INT,
@arg4 INT
AS
BEGIN
INSERT INTO Table1 (col1 ,col2)
VALUES (@arg1 , @arg2)
INSERT INTO Table2 (col3 ,col4)
VALUES (@arg3 , @arg4)
END
GO
坦白地说,事情不再那么简单了.
发布于 2014-06-09 21:25:55
这就是存储过程的要点。下面是一个示例:
CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName>
@Param1 INT,
@Param2 INT
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO TAB1
(COL1)
VALUES
(@Param1)
INSERT INTO TAB2
(COL1)
VALUES
(@Param2)
END
GO
发布于 2014-06-09 21:26:28
下面是您的代码:
create or replace procedure insert_data()
as
begin
insert into table1 values("a","b",100);
insert into table2 values("a1","b1",1001);
end
https://stackoverflow.com/questions/24133383
复制相似问题