我的存储过程有问题。我试图通过使用userID & GroupName
我希望能够不能拥有相同的组用户并且可以为不同的用户拥有相同的组名
ALTER PROCEDURE [dbo].[Insert_Group]
@UserID uniqueidentifier
,@GroupName varchar(100)
,@OutGroupID int out
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
if not EXISTS(select Groups.id from Groups where Groups.name = @GroupName and Groups.userID = userID)
begin
-- Insert statements for procedure here
INSERT INTO [ideaPark_DB].[dbo].[Groups]([userID], [name])
VALUES (@UserID, @GroupName)
SELECT @OutGroupID = SCOPE_IDENTITY();
end
else
SELECT @OutGroupID = (select Groups.id
from Groups
where Groups.name = @GroupName and Groups.userID = userID)
END