我在SQL Server中创建了一个数据库。我遵循这些:
Programmability -> Stored Procedures -> right click -> new stored procedures.
我在我的存储过程中编写了这段代码:
create procedure Insert_Users_legal
(
@name nvarchar(50),
@agentPosition int,
@email varchar(50),
@mobile char(11),
@phone char(11),
@postalCode char(10),
@address nchar(10)
)
as
set nocount on
insert into users_legal (name, agentPosition, email, mobile, phone, postalCode, address)
values (@name, @agentPosition, @email, @mobile, @phone, @postalCode, @address)
select CAST(scope_identity() as int) as id_legalUser
return
但是当我保存我的存储过程时,它不会显示在对象资源管理器中的存储过程文件夹中。
我该怎么办?
答案 0 :(得分:4)
首先点击执行,然后点击刷新
答案 1 :(得分:3)
执行以下语句,它必须在正确的数据库中创建存储过程:
/***** use the correct database *****/
USE municipalityDB;
GO
/***** Drop Procedure if already exist *****/
IF (OBJECT_ID('Insert_Users_legal') IS NOT NULL)
DROP PROCEDURE Insert_Users_legal
GO
/***** Now create the procedure *****/
create procedure Insert_Users_legal
(
@name nvarchar(50),
@agentPosition int,
@email varchar(50),
@mobile char(11),
@phone char(11),
@postalCode char(10),
@address nchar(10),
@id_legalUser INT OUTPUT --<-- use output param to get new id
)
as
BEGIN
set nocount on;
insert into users_legal (name,agentPosition,email,mobile,phone,postalCode,[address])
values (@name,@agentPosition,@email,@mobile,@phone,@postalCode,@address)
SELECT @id_legalUser = scope_identity(); --<-- No need to cast as INT
-- return --<-- Not required
END
GO
/***** Check if procedure exists *****/
Select name FROM sys.procedures
WHERE name LIKE '%Insert_Users_legal%'
GO