当前位置:首页 » 存储配置 » 存储用法

存储用法

发布时间: 2025-09-23 08:19:47

㈠ 在SQL中存储过程的一般语法是什么

1、 创建语法

createproc|procerepro_name

[{@参数数据类型}[=默认值][output],

{@参数数据类型}[=默认值][output],

....

]

as

SQL_statements

2、 创建不带参数存储过程

--创建存储过程

if(exists(select*fromsys.objectswherename='proc_get_student'))

dropprocproc_get_student

go

createprocproc_get_student

as

select*fromstudent;

--调用、执行存储过程

execproc_get_student;

3、 修改存储过程

--修改存储过程

alterprocproc_get_student

as

select*fromstudent;

4、 带参存储过程

--带参存储过程

if(object_id('proc_find_stu','P')isnotnull)

dropprocproc_find_stu

go

createprocproc_find_stu(@startIdint,@endIdint)

as

select*fromstudentwhereidbetween@startIdand@endId

go

execproc_find_stu2,4;

5、 带通配符参数存储过程

--带通配符参数存储过程

if(object_id('proc_findStudentByName','P')isnotnull)

dropprocproc_findStudentByName

go

createprocproc_findStudentByName(@namevarchar(20)='%j%',@nextNamevarchar(20)='%')

as

select*fromstudentwherenamelike@nameandnamelike@nextName;

go

execproc_findStudentByName;execproc_findStudentByName'%o%','t%';

(1)存储用法扩展阅读:

SQL存储过程优点:

1、重复使用。存储过程可以重复使用,从而可以减少数据库开发人员的工作量。

2、减少网络流量。存储过程位于服务器上,调用的时候只需要传递存储过程的名称以及参数就可以了,因此降低了网络传输的数据量。

3、安全性。参数化的存储过程可以防止SQL注入式攻击,而且可以将Grant、Deny以及Revoke权限应用于存储过程。

热点内容
java返回this 发布:2025-10-20 08:28:16 浏览:585
制作脚本网站 发布:2025-10-20 08:17:34 浏览:881
python中的init方法 发布:2025-10-20 08:17:33 浏览:574
图案密码什么意思 发布:2025-10-20 08:16:56 浏览:761
怎么清理微信视频缓存 发布:2025-10-20 08:12:37 浏览:678
c语言编译器怎么看执行过程 发布:2025-10-20 08:00:32 浏览:1005
邮箱如何填写发信服务器 发布:2025-10-20 07:45:27 浏览:251
shell脚本入门案例 发布:2025-10-20 07:44:45 浏览:108
怎么上传照片浏览上传 发布:2025-10-20 07:44:03 浏览:799
python股票数据获取 发布:2025-10-20 07:39:44 浏览:705