how to save data in strore prosedure
Loading
how to save data in strore prosedure
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Saurav KumarDevSocial team70.6K reputationPosted Oct 9, 2025, 2:44 AM EDT
To save data using a Stored Procedure in SQL Server, you first create the procedure in your database, then call it from your application (like ASP.NET Core or C#) with the required parameters.
Example ??
Step 1: Create the Stored Procedure in SQL Server
CREATE PROCEDURE SaveEmployeeData @Name NVARCHAR(50), @Email NVARCHAR(100), @Salary DECIMAL(10,2) AS BEGIN INSERT INTO Employees (Name, Email, Salary) VALUES (@Name, @Email, @Salary); END;Step 2: Call it from C# (ADO.NET Example)
using (SqlConnection con = new SqlConnection("YourConnectionString")) { SqlCommand cmd = new SqlCommand("SaveEmployeeData", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Name", "John"); cmd.Parameters.AddWithValue("@Email", "[email protected]"); cmd.Parameters.AddWithValue("@Salary", 55000); con.Open(); cmd.ExecuteNonQuery(); }That’s it — your data gets saved in the table through the stored procedure.
Stored procedures are more secure and efficient than inline SQL because they help prevent SQL injection and improve performance by caching execution plans.
Sandhiya PriyaRank #26 · 43.2K reputationPosted Oct 13, 2025, 2:48 AM EDT
How to save data using a stored procedure in SQL Server (the logic is similar in Oracle too).
I’ll give an example step by step.
1. Create a Table
First, you need a table where you want to save data. Example:
2. Create a Stored Procedure to Insert Data
A stored procedure allows you to encapsulate the SQL
INSERTlogic.CREATE PROCEDURE sp_AddEmployee @Name NVARCHAR(50), @Age INT, @Department NVARCHAR(50) AS BEGIN -- Insert data into the table INSERT INTO Employees (Name, Age, Department) VALUES (@Name, @Age, @Department); END3. Execute the Stored Procedure
You can call the procedure and pass the values to save data.
EXEC sp_AddEmployee @Name = 'Sandhiya', @Age = 25, @Department = 'IT';After this, a new row will be saved in the Employees table.
4. Optional: Check the Data
To make sure the data is saved:
Summary:
Create the table where data will be saved.
Write a stored procedure with parameters for the data.
Use
INSERT INTOinside the procedure.Execute the procedure with values to save the data.