Created
September 11, 2017 06:23
-
-
Save rts-rob/5ddab18719ffbe43e72e5c2b4dda30b1 to your computer and use it in GitHub Desktop.
User and Type example showing foreign key constraints and builtin uuid() function for generating id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE userType ( | |
id int NOT NULL, | |
description varchar(255) NOT NULL, | |
PRIMARY KEY (`id`) | |
); | |
CREATE TABLE user ( | |
id char(32) NOT NULL, -- use uuid() on INSERT | |
username varchar(24) NOT NULL, -- rob | |
passwordHash char(40) NOT NULL, -- c8fed00eb2e87f1cee8e90ebbe870c190ac3848c | |
passwordSalt char(36) NOT NULL, -- 880c991a-1827-4d60-8491-db415dcd1914 | |
userTypeId int NOT NULL, | |
PRIMARY KEY (`id`), | |
-- FOREIGN KEY (`userTypeId`) REFERENCES `mydb`.`userType` (`id`) | |
CONSTRAINT `fk_user_userType` | |
FOREIGN KEY (`userTypeId`) | |
REFERENCES `mydb`.`userType` (`id`) | |
ON DELETE NO ACTION | |
ON UPDATE NO ACTION | |
); | |
INSERT INTO user (id, username, password) | |
VALUES (uuid(), 'rob', 'somepassword'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment