我已经创建了一个基本的存储过程. [英] i have create a basic store procedure..when i m changing in this and execute it give me error that this name of SP already exit

查看:25
本文介绍了我已经创建了一个基本的存储过程.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码

USE AccountSystemTraining
GO

CREATE PROCEDURE dbo.precetics
AS
SELECT * FROM Department where id=1
GO

错误:

Msg 2714, Level 16, State 3, Procedure precetics, Line 4 有数据库中已经有一个名为precetics"的对象.

Msg 2714, Level 16, State 3, Procedure precetics, Line 4 There is already an object named 'precetics' in the database.

推荐答案

如果过程已经存在并且您需要更改它,那么您可能需要使用 ALTER 而不是 CREATE:

If the procedure already exists and you need to change it then you may need to use ALTER instead of CREATE:

ALTER PROCEDURE dbo.precetics AS SELECT * FROM Department where id=1 GO

注意:从 SQL Server 2016 你可以做到

Note: From SQL Server 2016 you can do

CREATE OR ALTER PROCEDURE dbo.precetics AS SELECT * FROM Department where id=1 GO

无论程序是否存在,它都将始终工作而不会出错.在以前的 SQL Server 中,您可以通过先测试是否存在来解决该问题.

which will always work without erroring regardless the procedure exists or not. In previous SQL server you can go around the issue by testing for existence first.

这篇关于我已经创建了一个基本的存储过程.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆