Using SQL Server I'm trying to do something really simple, but the solution is escaping me.
My database is throwing an error upon creation. I really just wanted to check if the customer.type is 'Student' that there is a '@' within there corresponding customer.email column.
Vice versa, if the customer.type is 'Faculty' that their customer.email column ends with a '@d.umn.edu'.
I've spent about half an hour working on this, and I stupidly can't get it to work.
Create table Customer
(
CID int identity(1,1) primary key,
F_name char(25),
M_name char(25),
L_name char(25),
type char(7),
street varchar(50),
city varchar(25),
state char(2),
zip numeric(5),
password varchar(25) not null,
email varchar(25) UNIQUE Not null,
Constraint CK_Customer_type check (type in ('Student','Faculty')),
Constraint CK_Customer_email check((type='Student' AND email like '%@%') OR (type='Faculty' AND email like'%@d.umn.edu'))-- this is throwing an error
)
INSERT INTO Customer (F_name, M_name, L_name, type, street, city, state, zip, password, email)
VALUES
('Jarvis', 'Marvin', 'Vinton', 'Student', '3525 Metz Lane', 'Runnemede St.', 'NJ', 08078, '[email protected]', 'Kohque4Oo'),
('Olivia', 'Audrey', 'Keele', 'Faculty', '2850 Snowbird Ln.', 'Waco', 'NE', 68460, '[email protected]', 'Blackdiamond26')
Note: it does not need to be in one constraint. Thanks in advance.