в общем я создал бд, но мне выдает ошибки: Сообщение 1767, уровень 16, состояние 0, строка 21 Внешний ключ «FK__subscript__reade__3D5E1FD2» ссылается на недопустимую таблицу «читатель». Сообщение 1750, уровень 16, состояние 1, строка 21 Не удалось создать ограничение или индекс. См. предыдущие ошибки.
вот мой код, помогите пожалуйста!
USE KrsDB1;
CREATE TABLE type_of_edition ( id INT NOT NULL PRIMARY KEY, name VARCHAR(50) NOT NULL );
CREATE TABLE edition ( id INT NOT NULL PRIMARY KEY, type_id INT NOT NULL, name VARCHAR(50) NOT NULL, periodicity VARCHAR(50) NOT NULL, subscription_cost DECIMAL(10,2) NOT NULL, FOREIGN KEY (type_id) REFERENCES type_of_edition(id) );
CREATE TABLE subscription ( edition_id INT NOT NULL, reader_id INT NOT NULL, department_id INT NOT NULL, date DATE NOT NULL, term INT NOT NULL, PRIMARY KEY (edition_id, reader_id, department_id), FOREIGN KEY (edition_id) REFERENCES edition(id), FOREIGN KEY (reader_id) REFERENCES reader(id), FOREIGN KEY (department_id) REFERENCES post_office_department(id) );
CREATE TABLE post_office_department ( id INT NOT NULL PRIMARY KEY, name VARCHAR(50) NOT NULL, address VARCHAR(100) NOT NULL, phone VARCHAR(20) NOT NULL );
CREATE TABLE reader ( id INT NOT NULL PRIMARY KEY, name VARCHAR(50) NOT NULL, address VARCHAR(100) NOT NULL );
CREATE TABLE delivery ( issue_id INT NOT NULL, department_id INT NOT NULL, reader_id INT NOT NULL, date DATE NOT NULL, PRIMARY KEY (issue_id, department_id, reader_id), FOREIGN KEY (issue_id) REFERENCES issue(id), FOREIGN KEY (department_id) REFERENCES post_office_department(id), FOREIGN KEY (reader_id) REFERENCES reader(id) );
CREATE TABLE printing_release ( issue_id INT NOT NULL PRIMARY KEY, department_id INT NOT NULL, date DATE NOT NULL, number_of_copies INT NOT NULL, FOREIGN KEY (issue_id) REFERENCES issue(id), FOREIGN KEY (department_id) REFERENCES post_office_department(id) );
CREATE TABLE issue ( id INT NOT NULL PRIMARY KEY, edition_id INT NOT NULL, name VARCHAR(50) NOT NULL, circulation INT NOT NULL, date DATE NOT NULL, FOREIGN KEY (edition_id) REFERENCES edition(id) );
Сообщение 1767, уровень 16, состояние 0, строка 21
Внешний ключ «FK__subscript__reade__3D5E1FD2» ссылается на недопустимую таблицу «читатель».
Сообщение 1750, уровень 16, состояние 1, строка 21
Не удалось создать ограничение или индекс. См. предыдущие ошибки.
вот мой код, помогите пожалуйста!
USE KrsDB1;
CREATE TABLE type_of_edition (
id INT NOT NULL PRIMARY KEY,
name VARCHAR(50) NOT NULL
);
CREATE TABLE edition (
id INT NOT NULL PRIMARY KEY,
type_id INT NOT NULL,
name VARCHAR(50) NOT NULL,
periodicity VARCHAR(50) NOT NULL,
subscription_cost DECIMAL(10,2) NOT NULL,
FOREIGN KEY (type_id) REFERENCES type_of_edition(id)
);
CREATE TABLE subscription (
edition_id INT NOT NULL,
reader_id INT NOT NULL,
department_id INT NOT NULL,
date DATE NOT NULL,
term INT NOT NULL,
PRIMARY KEY (edition_id, reader_id, department_id),
FOREIGN KEY (edition_id) REFERENCES edition(id),
FOREIGN KEY (reader_id) REFERENCES reader(id),
FOREIGN KEY (department_id) REFERENCES post_office_department(id)
);
CREATE TABLE post_office_department (
id INT NOT NULL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
address VARCHAR(100) NOT NULL,
phone VARCHAR(20) NOT NULL
);
CREATE TABLE reader (
id INT NOT NULL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
address VARCHAR(100) NOT NULL
);
CREATE TABLE delivery (
issue_id INT NOT NULL,
department_id INT NOT NULL,
reader_id INT NOT NULL,
date DATE NOT NULL,
PRIMARY KEY (issue_id, department_id, reader_id),
FOREIGN KEY (issue_id) REFERENCES issue(id),
FOREIGN KEY (department_id) REFERENCES post_office_department(id),
FOREIGN KEY (reader_id) REFERENCES reader(id)
);
CREATE TABLE printing_release (
issue_id INT NOT NULL PRIMARY KEY,
department_id INT NOT NULL,
date DATE NOT NULL,
number_of_copies INT NOT NULL,
FOREIGN KEY (issue_id) REFERENCES issue(id),
FOREIGN KEY (department_id) REFERENCES post_office_department(id)
);
CREATE TABLE issue (
id INT NOT NULL PRIMARY KEY,
edition_id INT NOT NULL,
name VARCHAR(50) NOT NULL,
circulation INT NOT NULL,
date DATE NOT NULL,
FOREIGN KEY (edition_id) REFERENCES edition(id)
);