简体   繁体   中英

can't save stored procedure in sql server DB

I want to use a stored procedure to add some data to SQL table but i can't save the stored procedure. What can i do?

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

It can be confusing the first time but to create a stored procedure, you must execute some code:

CREATE PROCEDURE YourSPName
    @MyParam1 nvarchar(MAX) = '',
    @MyParam2 nvarchar(MAX) = ''
AS
BEGIN
    SET NOCOUNT ON;
    -- Insert statements for procedure here
    SELECT * FROM YourTable
END
GO

In your case, instead of executing the code, you saved the code that was suppose to be executed in an .sql file on your local disk. To execute the code, look for a red exclamation mark in your menu panel or go to Query -> Execute.

SQL Management studio can create the code to generate a SP for you by right clicking the Stored Procedures folder then Stored Procedure... .

Note that you'll also have to execute some code if you want to modify an existing stored proc. In SQL Management studio, you can right click on an existing SP then select Modify .

You are saving procedure SearchByID on your local file system, naming the file AddToTable2 . This will not help you calling it in your code.

You need to create a new stored procedure on the server. You can do this by right-clicking Stored Procedures and chosing New stored procedure . This will create a file with an SQL statement starting with CREATE PROCEDURE ... . Then you'll have to execute that statement to create the procedure (ie, save it).

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM