Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 views
in Technique[技术] by (71.8m points)

sql server - 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

This is my code

USE AccountSystemTraining
GO

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

error:

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

Note: From SQL Server 2016 you can do

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...