I created a stored procedure for insert query and run the code. Successfully it executed. Now I want to remove one column from from that SP. How to do it?
CREATE PROCEDURE dbo.NewTerms_Insert
@ListID nvarchar(50) ,
@TimeCreated datetime ,
@TimeModified datetime ,
AS
BEGIN
SET NOCOUNT ON
INSERT INTO dbo.NewTerms
(
ListID ,
TimeCreated ,
TimeModified ,
)
VALUES
(
@ListID ,
@TimeCreated ,
@TimeModified ,
)
END
GO
I want to remove ListID from this Stored Procedure named dbo.NewTerms_Insert. How to do it?
Just ALTER
the procedure with removing that column.
ALTERPROCEDURE dbo.NewTerms_Insert
@TimeCreated datetime ,
@TimeModified datetime ,
AS
BEGIN
SET NOCOUNT ON
INSERT INTO dbo.NewTerms
(
TimeCreated ,
TimeModified ,
)
VALUES
(
@TimeCreated ,
@TimeModified ,
)
END
GO
Remove the column and alter the procedure:
ALTER PROCEDURE dbo.NewTerms_Insert
@TimeCreated datetime ,
@TimeModified datetime
AS
BEGIN
SET NOCOUNT ON
INSERT INTO dbo.NewTerms
(
TimeCreated ,
TimeModified
)
VALUES
(
@TimeCreated ,
@TimeModified
)
END
GO
Simply modify the procedure as you want (changing its interface and/or its body).
Before executing that script, run the following in order to make sure the previous version is removed:
IF OBJECT_ID('dbo.NewTerms_Insert', 'P') IS NOT NULL
DROP PROCEDURE dbo.NewTerms_Insert;
GO
Personally, I find it good practise to insert that fragment at the beginning of each script that creates/modifies a procedure or whatever.
Alter procedure and remove list column from insert statement and from value
Alter PROCEDURE dbo.NewTerms_Insert
(
@ListID nvarchar(50) ,
@TimeCreated datetime ,
@TimeModified datetime
)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO dbo.NewTerms
(
TimeCreated ,TimeModified
)
VALUES
(
@TimeCreated ,
@TimeModified
)
END
GO
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.