SQL Lab Manual 2012E.
C UOG
Sample Manual to create Tables and Stored Procedures using SQL
Create Database DBOne
Use DBOne
Write the following querry on SQL server
CREATE TABLE [dbo].[Login](
[UserName] [nvarchar](50) NOT NULL,
[Password] [nvarchar](50) NOT NULL,
[Role] [nvarchar](50) NOT NULL
)
CREATE TABLE [dbo].[Student](
[StudID] [nvarchar](50) PRIMARY KEY NOT NULL,
[FirstName] [nvarchar](50) NULL,
[FatherName] [nvarchar](99) NULL,
Sex [nvarchar](99) NULL,
Age int NULL,
)
CREATE TABLE [dbo].[FeedBack](
[FeedBackID] [int] IDENTITY(1,1) PRIMARY KEY NOT NULL,
[StudID] [nvarchar](50) NOT NULL,
[FeedBackDate] [datetime] NULL,
[Comment] [nvarchar](50) NULL,
FOREIGN KEY([StudID]) REFERENCES [dbo].[Student] ([StudID])
Now let see The Stored procedure for the above table to Insert, Update, Select and Delete
data from a table………………….
Syntax to create procedure
create proc (procedure) Name(
@column name datatype,
As
Begin
Activity………………
End
)
For Inserting Data into Student Table:-
create proc [dbo].[InsertintoStudent]
@StudID nvarchar(50) ,
@FirstName nvarchar(99),
@FatherName nvarchar(99),
@Sex nvarchar(99),
Prepared by Aleka M.
1
SQL Lab Manual 2012E.C UOG
@Age int
as
begin
insert into Student values(@StudID ,@FirstName ,@FatherName,@ Sex, @ Age )
insert into [Login] values (@StudID ,@StudID ,'Student') Commented [M1]: To insert data into login table that
end values are taken from student table…..
For Updating Data into Student Table:-
create proc [dbo].[UpdateStudent]
@StudID nvarchar(50) ,
@FirstName nvarchar(99),
@FatherName nvarchar(99),
@Sex nvarchar(99),
@Age int
as
begin
update Student set (FirstName =@FirstName , FatherName =@FatherName , Sex=@ Sex,
Age=@ Age
where StudID=@StudID)
end
For Selecting Data into Student Table:-
create proc [dbo].[SP_Student_Profile]
@StudID nvarchar(50)
as
begin
select * from Student
where StudID=@StudID
end
For Deleting Data into Student Table:-
create proc [dbo].[SP_Student_Profile]
@StudID nvarchar(50)
as
begin
delete * from Student
where StudID=@StudID
end
For Inserting Data into FeedBack Table:-
ALTER proc [dbo].[IN_FeedBack]
@StudID nvarchar(50),
@Comment nvarchar(50)
as
Prepared by Aleka M.
2
SQL Lab Manual 2012E.C UOG
begin
insert into FeedBack values(@StudID,,GETDATE(),@Comment) Commented [M2]: To insert current data form the PC
end
Prepared by Aleka M.
3