Pages

Ads 468x60px

Insert value in two tables with stored procedure

create proc Sp_InsertStudent(@name varchar(50),@marks int)

as

begin

insert into student(#name) values(@name)

end

begin

declare @id int

set @id= (select max(id) from Student)

insert into marks values(@id,@marks)

end

exec Sp_InsertStudent 'Sumit',87 //it will insert Name in Student table and marks and there corresponding Id in Makrs Table

No comments:

Post a Comment