
-- user is a reserved word in SQL, so cannot use as table name 
-- password is a reserved word in SQL, so cannot use as attribute
CREATE TABLE User_T (
	username	VARCHAR(12) NOT NULL,
	passwd 	VARCHAR(40) NOT NULL,
	fullName 	VARCHAR(30) NOT NULL,
	isAdmin 	boolean NOT NULL,
	CONSTRAINT 	pk_myuser PRIMARY KEY (username)
);

CREATE TABLE UserEmail_T (
	username VARCHAR(12) NOT NULL,
	email VARCHAR(30) NOT NULL,
	CONSTRAINT pk_useremail PRIMARY KEY (userName,email)
);

ALTER TABLE UserEmail_T
ADD CONSTRAINT fk_useremail FOREIGN KEY (username) REFERENCES User_T(userName);

INSERT INTO User_T(userName,passwd,fullname,isAdmin) VALUES
	('user1',SHA('user1'),'First1 Last1',true);
INSERT INTO User_T(userName,passwd,fullname,isAdmin) VALUES
	('user2',SHA('user2'),'First2 Last2', false);
	
INSERT INTO UserEmail_T(userName,email) VALUES 
	('user1','user1@villanova.edu');
INSERT INTO UserEmail_T(userName,email) VALUES 
	('user1','user1@gmail.com');
INSERT INTO UserEmail_T (userName,email) VALUES 
	('user2','user2@gmail.com');
	
