1、创建存储过程:
CREATE PROCEDURE proc_pr ---将create修改成alter可以修改存储过程;
AS
BEGIN
IF EXISTS(SELECT * FROM sysobjects WHERE TYPE='U' AND NAME='te')
BEGIN
PRINT '存在要删除的表te';
DROP TABLE te;
PRINT '已经删除表te';
END
ELSE
PRINT '不存在表te';
IF EXISTS(SELECT * FROM sysobjects WHERE TYPE='P' AND NAME='proc_jc')
BEGIN
PRINT '存在要删除的存储过程proc_jc';
DROP PROCEDURE proc_jc;
PRINT '已经删除存储过程proc_jc';
END
ELSE
PRINT '不存在存储过程proc_jc';
END
2、执行存储过程:
EXEC proc_pr;
3、查看存储过程proc_pr是否存在:
SELECT * FROM sysobjects WHERE TYPE='P' and name='proc_pr';
4、存储表te是否存在:
SELECT * FROM sysobjects WHERE TYPE='U' and name='te';
5、删除存储过程;
DROP PROCEDURE proc_pr;