如何将值插入同一存储过程的两个不同表中?
答案 0 :(得分:1)
这是存储过程的要点。这是一个例子:
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
答案 1 :(得分:1)
这是你的代码:
create or replace procedure insert_data()
as
begin
insert into table1 values("a","b",100);
insert into table2 values("a1","b1",1001);
end
答案 2 :(得分:1)
是的,很容易:
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
坦率地说,它不再那么直截了当......