patternsqlMinor
Database schema for Service Order Management project
Viewed 0 times
orderdatabaseprojectserviceformanagementschema
Problem
I'm a student and I've created this MySQL database schema for my Service Order Management academic project. I want to know if I need to improve it and, if so, how I could do that.
``
``
/*
* Table 'brands'
*/
CREATE TABLE brands (
brand_id INTEGER NOT NULL,
equipment_id INTEGER NOT NULL,
brand VARCHAR(45) NOT NULL,
CONSTRAINT pk_brand_id PRIMARY KEY (brand_id),
CONSTRAINT fk_equipment_id FOREIGN KEY (equipment_id) REFERENCES equipments
);
/*
* Table 'cities'
*/
CREATE TABLE cities (
city_id INTEGER NOT NULL,
state_id INTEGER NOT NULL,
city VARCHAR(50) NOT NULL,
CONSTRAINT pk_city_id PRIMARY KEY (city_id),
CONSTRAINT fk_state_id FOREIGN KEY (state_id) REFERENCES states
);
/*
* Table 'customers'
*/
CREATE TABLE customers (
customer_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
CONSTRAINT pk_customer_id PRIMARY KEY (customer_id),
CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES users
);
/*
* Table 'employees'
*/
CREATE TABLE employees (
employee_id INTEGER NOT NULL,
user_id INTEGER NOT NULL,
is_admin INTEGER NOT NULL,
CONSTRAINT pk_employee_id PRIMARY KEY (employee_id),
CONSTRAINT fk_user_id FOREIGN KEY (user_id) REFERENCES users,
CONSTRAINT ck_is_admin CHECK (is_admin IN (0, 1)) -- unsupported by MySQL
);
/*
* Table 'equipments'
*/
CREATE TABLE equipments (
equipment_id INTEGER NOT NULL,
equipment VARCHAR(45) NOT NULL,
CONSTRAINT pk_equipment_id PRIMARY KEY (equipment_id)
);
/*
* Table 'legal_users'
*/
CREATE TABLE legal_users (
user_id INTEGER NOT NULL,
cnpj CHAR(14) NOT NULL,
company_name VARCHAR(150) NOT NULL,
trade_name VARCHAR(100) NULL,
contact_name VARCHAR(50) NOT NULL,
mobile_phone CHAR(10) NULL,
work_phone CHAR(10) NULL,
CONSTRAINT pk_user_id PRIMARY KEY (user_id),
CONSTRAINT fk_user_id FOREIGN KEY (user_Solution
It looks fine. Two things to consider:
1, Distinct table for phone numbers:
It may not worth it, depends on the data.
2, Maybe you want to store some audit information about your data. (Hints: journal table in Oracle, Hibernate Envers)
+1:
1, Distinct table for phone numbers:
phone_number
id
user_id
type (home/work/mobile/etc)
numberIt may not worth it, depends on the data.
2, Maybe you want to store some audit information about your data. (Hints: journal table in Oracle, Hibernate Envers)
+1:
CHAR(40) for password - it's SHA-1? If you use SHA-256/SHA-512 it will be too short.Code Snippets
phone_number
id
user_id
type (home/work/mobile/etc)
numberContext
StackExchange Code Review Q#5645, answer score: 4
Revisions (0)
No revisions yet.