Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi frnds i have two table student details and student grade.
Student details contain columns
stu_id integer
stu_name
stu_place

student grade contains columns
stu_id
stu_grade

while saving i am going to send student name and grade,at that time by using single stored procedure i have to auto generate id and insert student details and student grade table.
Posted
Updated 11-Oct-12 3:57am
v2
Comments
joshrduncan2012 11-Oct-12 9:55am    
It's not clear what your question is.
Adersh Ram 11-Oct-12 9:59am    
Hi,

You can get the new id from "SELECT @@IDENTITY", insert the data to grade table using this id.

Thanks
ARam

1 solution

Hi ,
Check this
<br />
use Scope_Identity() or @@idetity 

also check on @@Error if any error happen
SQL
Create proc usp_name
( @name  varchar(30),@gard int)
as
begin
declare @id int 
insert into FirstTable
(name)
values
(@name)
set @id = @@identity --or scope_identity

insert into Secondtable 
(stid , grade)
value
(@id , @grade 
end

Best Regards
M.Mitwalli
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900