此问题已在此处有答案:
SQLite Exception near "course_gpa_id"(1个答案)
Create table fails if foreign keys are used in SQLite(2个答案)
3天前关闭。
创建表时不创建外键,尽管在另一个表中存在对它的引用
表客户:
CREATE TABLE customers (
customer_id INTEGER PRIMARY KEY AUTOINCREMENT,
customer_name VARCHAR(50),
contact_info VARCHAR(50));
表员工:
CREATE TABLE employees (
employee_id INTEGER PRIMARY KEY AUTOINCREMENT,
employee_name VARCHAR(50),
position VARCHAR(50),
hire_date DATETIME);
使用FOREIGN KEY的表顺序:
CREATE TABLE orders (
order_id INTEGER PRIMARY KEY AUTOINCREMENT,
customer_id INTEGER,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id),
employee_id INTEGER,
FOREIGN KEY (employee_id) REFERENCES employees(employee_id),
order_date DATETIME);
我创建了前两个表,并希望能够创建第三个表,但我得到了一个错误,对我来说似乎不合逻辑。
解析错误:靠近“employee_id”:语法错误(customer_id)REFERENCES customers(customer_id),employee_id INTEGER,FOREIGN
1条答案
按热度按时间tct7dpnv1#
外键是
CREATE TABLE
语句中的最后一个声明。确保在底部移动它们。