achievements_project/sql/CreateUserSP.sql

18 lines
804 B
Transact-SQL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

CREATE PROCEDURE [dbo].[CreateUser] (
@email varchar(254),
@username varchar(32),
@password char(256)
) AS
BEGIN TRANSACTION
IF EXISTS (SELECT Email FROM [User] WHERE Email = @email)
BEGIN
RAISERROR ('Email is already registered with an account.', 14, 1)
ROLLBACK TRANSACTION
RETURN 1
END
INSERT INTO [User] VALUES (@email, @username, @password)
COMMIT TRANSACTION
RETURN 0