CREATE TABLE Member
(
user_ID NUMBER NOT NULL ,
user_password VARCHAR2(50) NULL CONSTRAINT Email_153906048 CHECK (user_password IN ('%@%')),
user_email VARCHAR2(50) NULL CONSTRAINT Email_1275780631 CHECK (user_email IN ('%@%')),
user_firstName VARCHAR2(20) NULL ,
user_lastName VARCHAR2(20) NULL ,
user_type VARCHAR2(8) NULL CONSTRAINT Type_1346517516 CHECK (user_type IN ('Artist', 'Follower')),
CONSTRAINT XPKUser PRIMARY KEY (user_ID)
);
答案 0 :(得分:6)
这将检查它是否包含至少一个'@':
CHECK (user_email LIKE '%@%')
确保'@'两边都有东西:
CHECK (user_email LIKE '%_@_%')
可以使用正则表达式进行更具体的检查。
答案 1 :(得分:2)
要添加Tony的正确答案,如果您决定要进行更多检查,可以使用多个子句扩展检查约束,例如:
CHECK(
user_email like '%@%.%' -- Must contain at least one @ and one subsequent .
and user_email NOT like '%..%' -- Cannot have two periods in a row
and user_email NOT like '%@%@%' -- Cannot have two @ anywhere
and user_email NOT like '%.@%'AND user_email NOT like '%@.%' -- Cant have @ and . next to each other
and replace(translate(user_email,'[ &'',":;!=\/()<>]*%',' '),' ') = user_email -- check for invalid characters
)
尽管您不想意外排除有效地址,但不要过于苛刻。
答案 2 :(得分:-1)
是。您可以使用HttpUtility.UrlEncode("my méssägë hérë")
符号的验证检查创建触发器。
这样的事情:
@