Introduction
Hello frnds this is
my first article in sql server
today I will start with create table and
insert data into the table using stored
procedure .As you all well know that how can we directly create table in
sql server
And put data into on right click onto the table and using
edit table option put some data into table (depends on which version you are using
of sql server.)But now we will use stored procedure .There are some benefits of
using stored procedure in sql server because it quick in response and more
secure from coding point of you once you create procedure you will be able to
use it just call by procedure name. So let we start with create a table and
after that I will create procedure for inserting data.
Step 1:To create table first right click on database name
and open new query window and write the following code
//Create Table Command
Create Table Demo_User(
[User_ID] [int] IDENTITY (1,1) not null,
[User_Name] [varchar](100) not null,
[User_Mail] [varchar](100) not null,
CONSTRAINT
[PK_demo_user] PRIMARY KEY
CLUSTERED
(
[User_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS
= ON) ON [PRIMARY]
) ON [PRIMARY]
Now table has been created.
Step 2:Now again open new query editor window to write the
stored procedure code for inserting data.
create procedure sp_insert_DemoUser
@User_Name varchar(100),
@User_Mail varchar(100)
as
begin
insert into Demo_User([User_Name],[User_Mail])values (@User_Name,@User_Mail)
end
Here is my simple insert procedure code Blue one is standard text which we have to
write in this manner “@” is use to
declare variable in Stored Procedure .
So try this way and in next tutorials I will explain you to
how to execute stored procedure and use it in C#.
Thanks guys
0 comments:
Post a Comment