zoukankan      html  css  js  c++  java
  • 让用户更改自己邮箱

    您的程序,邮箱也可以当作一个唯一值,每人只能注册一次。在让用户更改自己邮箱前,得判断邮箱是否已经被人注册。

    请参考下面存储过程:

    代码
    CREATE PROCEDURE [dbo].[usp_Users_UpdateEmail]
    (
        
    @ID tinyint,
        
    @Email nvarchar(150)
    )
    AS    
    --判断邮箱地址是否存在
    IF EXISTS(SELECT TOP 1 * FROM [Users] WHERE [Email] = @Email AND [Email] <> '' AND [Email] IS NOT NULL AND [UsersId] <> @ID)
    BEGIN
        
    --如果存在,提示给用户。
        RAISERROR(N'此邮箱:%s已经存在,无法更新!',16,1,@Email)
        
    RETURN
    END
    BEGIN TRANSACTION
    DECLARE @err int
        
    --更新邮箱
        UPDATE [Users] SET [Email] = @Email WHERE [UsersId] = @ID
        
    SET @err = @@ERROR
        
    IF @err <> 0    
    BEGIN
        
    ROLLBACK TRANSACTION        
    END
        
    COMMIT TRANSACTION
  • 相关阅读:
    Add Two Numbers
    Reverse Linked List II
    Reverse Linked List
    Remove Duplicates from Sorted List
    Remove Duplicates from Sorted List II
    Partition List
    Intersection of Two Linked Lists
    4Sum
    3Sum
    2Sum
  • 原文地址:https://www.cnblogs.com/insus/p/1932766.html
Copyright © 2011-2022 走看看