我正在尝试创建程序,该程序正在生成错误说明
表中标识列的显式值tblRegisterUser
只能在使用列列表时指定,并且IDENTITY_INSERT is ON
。
我试图用 包围插入语句INDENTITY_INSERT to ON
,但这也不起作用。我错过了什么还是我包含的子查询有错误?
以下是存储过程
CREATE PROCEDURE dbo.spInsertUserRegister
(
@FirstName nvarchar(50),
@LastName nvarchar(50),
@Username nvarchar(50),
@Password nvarchar(50),
@Designation nvarchar(50),
@Department nvarchar(50),
@IsAdmin bit
)
AS
BEGIN
INSERT INTO tblRegisterUser Values
(
@FirstName, @LastName, @Username, @Password,@Designation,@Department,@IsAdmin
)
DECLARE @UID INT
SET @UID = @@IDENTITY
INSERT INTO tblLogin(Username,Password,UID,IsAdmin)
Values(@Username, @Password, @UID,(SELECT IsAdmin FROM tblRegisterUser WHERE Username=@Username AND Password=@Password))
END