Basics - MySQL - 14.Create SoftUni Database - 72/100 !!!
Здравейте, моля за малко помощ. Judge ми дава 72/100 точки. Гърмят ми първите 3 теста. Моля за малко помощ не мога да разбера къде греша. Благодаря предварително.
Условие :
14.Create SoftUni Database
Now create bigger database called soft_uni. You will use database in the future tasks. It should hold information about
- towns (id, name)
- addresses (id, address_text, town_id)
- departments (id, name)
- employees (id, first_name, middle_name, last_name, job_title, department_id, hire_date, salary, address_id)
Id columns are auto incremented starting from 1 and increased by 1 (1, 2, 3, 4…). Make sure you use appropriate data types for each column. Add primary and foreign keys as constraints for each table. Use only SQL queries. Consider which fields are always required and which are optional. Submit your CREATE TABLE statements as Run queries & check DB.
Решение:
CREATE TABLE towns(
id INT(20) PRIMARY KEY AUTO_INCREMENT NOT NULL,
name VARCHAR(100) NOT NULL
);
CREATE TABLE addresses(
id INT(20) PRIMARY KEY AUTO_INCREMENT NOT NULL,
addres_text VARCHAR(100) NOT NULL,
town_id INT(20) NOT NULL
);
CREATE TABLE departments(
id INT(10) PRIMARY KEY AUTO_INCREMENT NOT NULL,
name VARCHAR(100) NOT NULL
);
CREATE TABLE employees(
id INT(10) PRIMARY KEY AUTO_INCREMENT NOT NULL,
first_name VARCHAR(100) NOT NULL,
middle_name VARCHAR(100) NOT NULL,
last_name VARCHAR(100) NOT NULL,
job_title VARCHAR(100) NOT NULL,
department_id INT(20) NOT NULL,
hire_date DATE NOT NULL,
salary DOUBLE(10,2) NOT NULL,
address_id INT(20) NOT NULL
);
ALTER TABLE addresses ADD CONSTRAINT fk_addresses_towns FOREIGN KEY (town_id) REFERENCES towns(id);
ALTER TABLE employees ADD CONSTRAINT FK_address_id FOREIGN KEY (address_id) REFERENCES addresses(id);
ALTER TABLE employees ADD CONSTRAINT FK_department_id FOREIGN KEY (department_id) REFERENCES departments (id);