# "AddUser" Stored Procedure

Description:

This stored procedure adds a new user to the Users table with the appropriate Role.

Definition:

    	CREATE     PROCEDURE TT_AddUser
    	(
    		@UserName nvarchar(50),
    		@Password nvarchar(50),
    		@DisplayName nvarchar(50),
    		@RoleID int
    	)
    	AS

    	--Verify that the UserName is not being added to a UserName that already exists
    	IF Not Exists (SELECT UserName FROM TT_Users WHERE UserName=@UserName)
    	BEGIN

    		INSERT INTO TT_Users
    		(
    			Username,
     			Password,
     			DisplayName,
    			RoleID
    		)
    		VALUES
    		(
    			@UserName,
     			@Password,
     			@DisplayName,
    			@RoleID
    		)

    		SELECT
    			@@Identity AS UserID
    	END
    	ELSE
    		SELECT -2 AS UserID

Database Tables Used:

The primary key in the Users table is the UserID identity field.