11.12存储过程复习及例题
2012-11-12 15:09
120 查看
存储过程:相当于C#中的方法(有参数,返回值)
向特定表中插入记录的存储过程
注册
向T_users 插入一条用户写好的信息
use UserDB1
seclect * from T_users
Create proc usp_Registor
@name varchar(50),
@pwd varchar(50),
@email varchar(50)
as begin
insert into T_users(FuserName,Fpassword,Femail) values(@name,@password,@email)
end
exec usp_Registor'白白','111','bai@126.com'
---------删除存储过程删除特定表中的一条记录
use School
select * from Class
create proc usp_Student_Delete
@sId int
as begin
delete from Student where sId=@sId
end
exec usp_Student_Delete @sId=14
--------------修改特定表中的某条记录(更新操作)
select * from Class
insert into Class values('Net','优秀班集体')
insert into Class values('Java','优秀班集体')
create proc usp_Class_update
@Cid int,
@Cname varchar(50),
@CDes varchar(50)
as begin
upate Class set cName=@Cname,cDescription=@CDes where
clsId=@Cid
end
exec usp_Class_update 10,'3G','优秀班集体'
----------------查询所有记录
create proc usp_Class_SelectAll
as
begin
select * from Class
end
exec usp_Class_SelectAll
------------针对特定表分页的存储过程
create proc usp_MyStudent_GetDateByPageIndex
@pageSize int=10, //默认每页10 条
@pageIndex int
as
begin
select * from
(select *,Row_Number() over(order by Fid) as rowIndex from MyStudent)
as tbl
where tb1.rowIndex between (@pageSize*(@pageIndex-1)+1)and @pageSize*@pageIndex
end
exec usp_MyStudent_GetDateByPageIndex
5,3
向特定表中插入记录的存储过程
注册
向T_users 插入一条用户写好的信息
use UserDB1
seclect * from T_users
Create proc usp_Registor
@name varchar(50),
@pwd varchar(50),
@email varchar(50)
as begin
insert into T_users(FuserName,Fpassword,Femail) values(@name,@password,@email)
end
exec usp_Registor'白白','111','bai@126.com'
---------删除存储过程删除特定表中的一条记录
use School
select * from Class
create proc usp_Student_Delete
@sId int
as begin
delete from Student where sId=@sId
end
exec usp_Student_Delete @sId=14
--------------修改特定表中的某条记录(更新操作)
select * from Class
insert into Class values('Net','优秀班集体')
insert into Class values('Java','优秀班集体')
create proc usp_Class_update
@Cid int,
@Cname varchar(50),
@CDes varchar(50)
as begin
upate Class set cName=@Cname,cDescription=@CDes where
clsId=@Cid
end
exec usp_Class_update 10,'3G','优秀班集体'
----------------查询所有记录
create proc usp_Class_SelectAll
as
begin
select * from Class
end
exec usp_Class_SelectAll
------------针对特定表分页的存储过程
create proc usp_MyStudent_GetDateByPageIndex
@pageSize int=10, //默认每页10 条
@pageIndex int
as
begin
select * from
(select *,Row_Number() over(order by Fid) as rowIndex from MyStudent)
as tbl
where tb1.rowIndex between (@pageSize*(@pageIndex-1)+1)and @pageSize*@pageIndex
end
exec usp_MyStudent_GetDateByPageIndex
5,3
相关文章推荐
- 数据库复习总结(20)-存储过程以及.net调用存储过程
- 数据库复习--三范式、基本数据类型、完整性、存储过程
- ssh三大框架,三层架构 整合测试!完整分页代码,JdbcTemplate等测试,存储过程调用,留着以后复习吧
- 【数据库复习_存储过程】
- Oracle 复习(序列,建表,查询,存储过程,异常)
- SQL Server 2008中文版标准教程读书笔记 存储过程与触发器(复习SQL Server 六)
- 项目整理复习一:SQL高效分页存储过程
- [导入]复习sql语句之存储过程
- 温故而知新--sql存储过程复习
- sql语句存储过程简单复习
- 温故而知新--sql存储过程复习
- 温故而知新--sql存储过程复习
- 存储过程简单定义,表复习
- 存储过程复习
- ssh三大框架,三层架构 整合测试!完整分页代码,JdbcTemplate等测试,存储过程调用,留着以后复习吧
- 存储过程例题(1)
- oracle 存储过程语法总结及相关写法复习 if、case、loop等
- 存储过程复习
- 存储过程 if 复习 while 学习
- 如何判断存储过程中,T-SQL语句是否执行?