存储过程的增删改查
增
CREATE PROCEDURE [dbo].[Add_Admin]
(
@UserName nvarchar(50),
@Password nvarchar(50),
@LastLoginIP nvarchar(50),
@LastLoginTime Datetime
)
AS
INSERT INTO
Admin
(
UserName,
Password,
LastLoginIP,
LastLoginTime
)
Values
(
@UserName,
@Password,
@LastLoginIP,
@LastLoginTime
)
RETURN @@Identity
GO
删
CREATE PROCEDURE [dbo].[Delete_Admin]
(
@ID int
)
AS
DELETE Admin WHERE ID=@ID
GO
改
CREATE PROCEDURE [dbo].[Update_Admin]
(
@ID int,
@UserName nvarchar(50),
@Password nvarchar(50),
@LastLoginIP nvarchar(50),
@LastLoginTime Datetime
)
AS
UPDATE
Admin
SET
UserName =@UserName ,
Password=@Password,
LastLoginIP=@LastLoginIP,
LastLoginTime=@LastLoginTime
WHERE
ID=@ID
GO
查
CREATE procedure Get_Product
(@startIndex int,
@endIndex int,
@docount bit)
as
set nocount on
if(@docount=1)
select count(*) AS Counts from Product
else
begin
declare @indextable table(id int identity(1,1),nid int)
set rowcount @endIndex
insert into @indextable(nid) select ID from Product order by ID desc
select * from Product O,@indextable t where O.ID=t.nid
and t.id between @startIndex and @endIndex order by t.id
end
set nocount off
GO