Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I have 2 tables, custlogin and custinfo

custlogin:

custid int primary key auto notnull
custusename varchar(25)
custpassword varchar(50)
custinfo:

custid foriegnkey custlogin.custid ondelete set NULL
custfirstname varchar(25)
custlastname varchar(25)
custaddress varchar(100)

want to write a stored procedure which will insert into both tables
Posted
Comments
Kornfeld Eliyahu Peter 29-Apr-15 7:04am    
And what have you tried[^] so far?
Unni R 29-Apr-15 7:07am    
HOW TO INSERT THESE TWO TABLES WITH STORED PROCEDURE
Tomas Takac 29-Apr-15 7:28am    
Don't shout. Show what you are doing now, explain what problems you are facing. What you wrote in your question so far is more like assignment not a question really.
John C Rayan 29-Apr-15 7:46am    
Look at my solution, which is tested in SQL 2008 R2 and worked fine.

1 solution

CREATE PROCEDURE usp_ins_cust(@cust_un varchar, 
                              @cust_pw varchar, 
                              @cust_fn varchar, 
                              @cust_ln varchar,
                              @cust_addr varchar)
AS
BEGIN TRY
     BEGIN TRANSACTION
           INSERT INTO custlogin(custusename, custpassword) values (@cust_un, @cust_pw)
           INSERT INTO custinfo(custid, custfirstname, custlastname, custaddress) 
            values (SCOPE_IDENTITY(), @cust_fn, @cust_ln, @cust_addr)
     COMMIT
 END TRY
 BEGIN CATCH
  ROLLBACK
 END CATCH
 
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