Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7933255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:16:29+00:00 2026-06-03T21:16:29+00:00

Here is my database. I want to make a stored procedure to insert data

  • 0

Here is my database. I want to make a stored procedure to insert data into the Reservation table. I want to insert room_id, data check-in and other fields but instead of guest_id I want to put first name, last name, Phone and other fields from the Guest table. Is this possible?

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:16:30+00:00Added an answer on June 3, 2026 at 9:16 pm

    I would create 2 stored procedures. one for saving the guest info and one for saving the reservation info.

    CREATE PROCEDURE SaveGuest(@firstName varcahr(50),@lastName varchar(50),@phone varchar(15))
    AS
     BEGIN
    
        INSERT INTO Guest(FirstName,LastName,Phone) VALUES (@firstName,@lastName,@phone);
        RETURN SCOPE_IDENTITY()
    
     END
    

    Procedure to call Second Proc

    CREATE PROCEDUE SaveReservation(@roomId int,@guestId int,@price decimal)
    AS
     BEGIN
       INSERT INTO Reservation(Room_ID,Guest_ID,Price) VALUES (@roomID,@guestId,@price)
       RETURN SCOPE_IDENTITY()
     END
    

    This is a sample. You need to add field for all your db columns which is not null.

    Now create 2 methods to save these data. SaveGuest and SaveReservation. Return the Newly Saved Guest ID from your SaveGuest method. Now in your action method call, the SaveGuest method first. check the return value of the method. If it is a valid number, That means the guest info is saved. USe that Guest ID in saving the Second part (Reservation); Something like this

    public ActionResult SAve(YourViewMolde model)
    {
    int guestId=  SaveGuest("john","alex",....);
    if(guestID>0)
     {
       SaveReservation(guestId,34,...);
     }
     else
     {
       model.AddModelError("","Error in saving Guest info!");
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to do following: Make Oracle stored procedure for read all data from
I want display data from database in Listbox...Here is my code, It is not
Just getting into SQL stored queries right now... anyway, here's my database schema (simplified
I want to retrieve values from SQLite database in my Android application. Here in
Here is my php that retrieves image from mysql database. I want to resize
I want to create a PDO class for handling data base connections. Here is
I am trying to map a legacy database here and I'm running into a
I have a database table structure as follow: datatype data mytable now datatype has
This is the stored procedure for any reason this perma-looping I have to make
I have a stored procedure that adds an object to the database and returns

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.