Create Database table with required store procedure

First we need to create to create required table into out Sql Management studio . Here is the script to create table and store procedure .

Here is the script to create tables . I named it Student 

 
CREATE TABLE [dbo].[Student](
[Student_Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NULL,
[Address] [nvarchar](100) NULL,
[EmailID] [nvarchar](50) NULL,
[Mobile] [varchar](10) NULL,
)

Here is the script to create store procedure . The first store procedure is to add new record into database  and i named it AddNewStudent.

CREATE PROCEDURE [dbo].[AddNewStudent]
(
@Name   nvarchar(20),
@Address nvarchar(60),
@EmailId  nvarchar(15),
@Mobile   nvarchar(15)
)
AS
insert into Student
(Name,  Address, EmailId, Mobile)
values
(@Name, @Address, @EmailId,@Mobile)
RETURN


Here is the procedure to update student records .

CREATE PROCEDURE [dbo].[UpdateStudent]
(
@Student_Id int,
@Name nvarchar(20),
@Address nvarchar(60),
@EmailID nvarchar(15),
@Mobile nvarchar(15)
)
AS
update Student
set
Name = @Name, 
Address = @Address, 
EmailID = @EmailID, 
Mobile = @Mobile 
where Student_Id = @Student_Id
RETURN


Here is the script for delete student records .

CREATE PROCEDURE [dbo].[DeleteStudent]
(
@Student_Id int
)
AS
delete from Student where Student_Id = @Student_Id
RETURN

GO

No comments:

Post a Comment