存储过程基础知识汇总

xiaoxiao2021-02-28  99

--查询所有存储过程select * from sys.objects where type = 'P'; --修改存储过程alter proc proc_get_studentasselect * from student; --调用、执行存储过程exec proc_get_student; -------------------------------- --创建存储过程if (exists (select * from sys.objects where name = 'proc_get_student')) drop proc proc_get_studentgocreate proc proc_get_studentas select * from student; ----------------------------------- --带参存储过程if (object_id('proc_find_stu', 'P') is not null) drop proc proc_find_stugocreate proc proc_find_stu(@startId int, @endId int)as select * from student where id between @startId and @endIdgoexec proc_find_stu 2, 4; ------------------------------------- --带通配符参数存储过程if (object_id('proc_findStudentByName', 'P') is not null) drop proc proc_findStudentByNamegocreate proc proc_findStudentByName(@name varchar(20) = '%j%', @nextName varchar(20) = '%')as select * from student where name like @name and name like @nextName;goexec proc_findStudentByName;exec proc_findStudentByName '%o%', 't%';

转载请注明原文地址: https://www.6miu.com/read-57235.html

最新回复(0)