SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL'; CREATE DATABASE IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 ; SHOW WARNINGS; USE `mydb`; -- ----------------------------------------------------- -- Table `mydb`.`users` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`users` ( `id` INT NOT NULL AUTO_INCREMENT COMMENT 'Unique ID for this user' , `login` VARCHAR(30) NOT NULL COMMENT 'Unique login (nickname) for this user' , `password` VARCHAR(30) NOT NULL COMMENT 'Private password for login for this user' , `first_name` VARCHAR(30) NOT NULL COMMENT 'First name for this user' , `last_name` VARCHAR(30) NOT NULL COMMENT 'Last name for this user' , `user_group_id` INT NOT NULL COMMENT 'User group this user is related to' , `create_dt` DATETIME NOT NULL COMMENT 'Date and time of the creation of this user' , `change_dt` DATETIME NOT NULL COMMENT 'Date and time of the change of this user' , PRIMARY KEY (`id`) , CONSTRAINT `fk_users_user_groups` FOREIGN KEY (`user_group_id` ) REFERENCES `mydb`.`user_groups` (`id` ) ON DELETE NO ACTION ON UPDATE NO ACTION) COMMENT = 'USR - Users registered in the application; SHOW WARNINGS; CREATE UNIQUE INDEX users_login ON `mydb`.`users` (`login` ASC) ; SHOW WARNINGS; CREATE INDEX fk_users_user_groups ON `mydb`.`users` (`user_group_id` ASC) ; SHOW WARNINGS; -- ----------------------------------------------------- -- Table `mydb`.`user_groups` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `mydb`.`user_groups` ( `id` INT NOT NULL AUTO_INCREMENT COMMENT 'Unique ID for this user group' , `name` VARCHAR(30) NOT NULL COMMENT 'Name for this user group' , `create_dt` DATETIME NOT NULL COMMENT 'Date and time of the creation of this user group' , `change_dt` DATETIME NOT NULL COMMENT 'Date and time of the change of this user group' , PRIMARY KEY (`id`) ) COMMENT = 'USRGRP - User groups available to users in the application; SHOW WARNINGS; CREATE UNIQUE INDEX user_groups_name ON `mydb`.`user_groups` (`name` ASC) ; SHOW WARNINGS; SET SQL_MODE=@OLD_SQL_MODE; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;