In this post I would like to show how to create a stored procedure in
SQL Server to insert data into a table .If you never had any experiences to
create a stored procedure in SQL Server 2008 , let's try with me. I'll
show you step by step.
I have a table, Tbl_Supplier as picture below:
CREATE PROCEDURE sp_addSupplier
@supplierID nvarchar(50),
@employeeID nvarchar(50),
@supname nvarchar(50),
@address nvarchar(50),
@tel nvarchar(50),
@website nvarchar(50),
@email nvarchar(50),
@datein date
AS
INSERT INTO Tbl_Supplier (SuppllierID,EmployeeID,SupplierName,[Address],Tel,Website,Email,Datein) VALUES (@supplierID,@employeeID,@supname, @address,@tel,@website,@email,@datein)
Click on Execute to execute query.
You will get a stored procedure to insert data into a table .....enjoy it
I have a table, Tbl_Supplier as picture below:
Figure 1: Tbl_Supplier |
To create a stored procedure, go to Object Explorer --> Click on your Database name -->Click on Programmability -->Right click on Stored Procedures , and then choose New Stored Procedure.
Figure 2: Create a new stored procedure |
Figure 3 : New stored procedure (SQLQuery3.sql) |
3. Press Ctrl+A to select all and delete all statement in SQLQuery3.sql ,and then write code insert values to table as below :
CREATE PROCEDURE sp_addSupplier
@supplierID nvarchar(50),
@employeeID nvarchar(50),
@supname nvarchar(50),
@address nvarchar(50),
@tel nvarchar(50),
@website nvarchar(50),
@email nvarchar(50),
@datein date
AS
INSERT INTO Tbl_Supplier (SuppllierID,EmployeeID,SupplierName,[Address],Tel,Website,Email,Datein) VALUES (@supplierID,@employeeID,@supname, @address,@tel,@website,@email,@datein)
Click on Execute to execute query.
Figure 4: Execute Query |
Create stored procedure to insert data into a table in SQL Server
Reviewed by BeiLover
on
7:09 PM
Rating:
No comments: