我在从XAMPP
运行的mysql上运行以下查询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';
DROP SCHEMA IF EXISTS htmlProject;
CREATE SCHEMA htmlProject;
USE htmlProject;
--
-- Table structure for table `actor`
--
CREATE TABLE ACTORS (
actor_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
actor_name VARCHAR(50) NOT NULL,
joined_on DATETIME NOT NULL,
actor_password VARCHAR(50) NOT NULL,
PRIMARY KEY (actor_id),
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE TAGS (
tag_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
tag_name VARCHAR(25) NOT NULL,
PRIMARY KEY (tag_id)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE FILES (
files_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
files_name VARCHAR(45) NOT NULL,
uploaded_on DATETIME NOT NULL,
PRIMARY KEY (files_id),
actor_id SMALLINT UNSIGNED NOT NULL,
KEY idx_fk_actor_id (actor_id),
CONSTRAINT `fk_files_actors` FOREIGN KEY (actor_id) REFERENCES ACTORS(actor_id) ON DELETE RESTRICT ON UPDATE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE FILESTAG (
files_tag_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
tag_id SMALLINT UNSIGNED NOT NULL,
files_id SMALLINT UNSIGNED NOT NULL,
PRIMARY KEY (files_tag_id)
KEY idx_fk_tag_id (tag_id),
KEY idx_fk_files_id (files_id),
CONSTRAINT `fk_files_tags` FOREIGN KEY (tag_id) REFERENCES TAGS (tag_id) ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT `fk_tags_files` FOREIGN KEY (files_id) REFERENCES FILES (files_id) ON DELETE RESTRICT ON UPDATE CASCADE
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
但我仍然在以下几行中收到错误1064
ERROR 1064 (42000) at line 27 in file: 'C:\Users\hanyd\Desktop\HTML project\html_project_query2.sql': You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')ENGINE=InnoDB DEFAULT CHARSET=utf8' at line 7
Query OK, 0 rows affected (0.18 sec)
Query OK, 0 rows affected (0.17 sec)
ERROR 1064 (42000) at line 53 in file: 'C:\Users\hanyd\Desktop\HTML project\html_project_query2.sql': You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(files_tag_id),
KEY idx_fk_tag_id (tag_id),
KEY idx_fk_files_id (files_id),
' at line 5
我绝对不知道为什么会这样,即使我之前写过类似的查询,绝对没有这种错误。在这里我的注意力是什么?
答案 0 :(得分:2)
你错过了一个逗号:
CREATE TABLE FILESTAG (
files_tag_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
tag_id SMALLINT UNSIGNED NOT NULL,
files_id SMALLINT UNSIGNED NOT NULL <---- Add comma here
你有一个逗号,其中不应该有一个:
CREATE TABLE ACTORS (
actor_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
actor_name VARCHAR(50) NOT NULL,
joined_on DATETIME NOT NULL,
actor_password VARCHAR(50) NOT NULL,
PRIMARY KEY (actor_id), <--- REMOVE this comma
)ENGINE=InnoDB DEFAULT CHARSET=utf8;