2011-06-13 3 views
0

다음 SQL 쿼리의 문제점을 알고있는 사람이 있습니까?SQL 구문 오류?

CREATE TABLE IF NOT EXISTS PrWorlds (     # World table 
worldid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, 
worldname VARCHAR(32) NOT NULL UNIQUE     # Name of world 
); 

CREATE TABLE IF NOT EXISTS PrEntries (     # User/Group table 
entryid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, 
name VARCHAR(32) NOT NULL,        # Name of user/group 
worldid INTEGER NOT NULL,        # ID of the world the  user/group belongs to 
type TINYINT NOT NULL,         # Type denotes the entry type.  0 for a user, 1 for a group 
CONSTRAINT NameWorld UNIQUE (name, worldid, type), 
ENTRYINDEX 
FOREIGN KEY(worldid) REFERENCES PrWorlds(worldid) ON DELETE CASCADE ON UPDATE CASCADE 
); 

CREATE TABLE IF NOT EXISTS PrPermissions (       # Table of  permission nodes 
permid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
permstring VARCHAR(64) NOT NULL,          # Permission node 
entryid INTEGER NOT NULL,            # Entry whom this  node belongs to 
CONSTRAINT PrEntryPerm UNIQUE (entryid, permstring), 
FOREIGN KEY(entryid) REFERENCES PrEntries(entryid) ON DELETE CASCADE ON UPDATE CASCADE 
); 

CREATE TABLE IF NOT EXISTS PrInheritance (     # Table of parent-child  relationships 
uinheritid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
childid INTEGER NOT NULL,         # Child entry 
parentid INTEGER NOT NULL,         # Parent entry 
parentorder INTEGER NOT NULL,        # Denotes order of  inheritance. 
                  # Groups override other  groups' permissions/data 
                  # below them in the results 
CONSTRAINT PrParent UNIQUE (childid, parentid), 
CONSTRAINT PrOrderedInheritance UNIQUE (childid, parentorder), 
CONSTRAINT PrNoSelfInherit CHECK (childid <> parentid), 
FOREIGN KEY(childid) REFERENCES PrEntries(entryid) ON DELETE CASCADE ON UPDATE CASCADE, 
FOREIGN KEY(parentid) REFERENCES PrEntries(entryid) ON DELETE CASCADE ON UPDATE CASCADE 
); 

CREATE TABLE IF NOT EXISTS PrWorldBase (  # Table of the default groups in that world 
worldid INTEGER NOT NULL, 
defaultid INTEGER,       # Default group 
FOREIGN KEY(worldid) REFERENCES PrWorlds(worldid) ON DELETE CASCADE ON UPDATE CASCADE, 
FOREIGN KEY(defaultid) REFERENCES PrEntries(entryid) ON DELETE CASCADE ON UPDATE CASCADE 
); 

CREATE TABLE IF NOT EXISTS PrData (
dataid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
entryid INTEGER NOT NULL ,     # ID entry whom this data node belongs to 
path VARCHAR(64) NOT NULL,     # Path to data node (e.g. "prefix", "build") 
data VARCHAR(64) NOT NULL,     # Data node in string form (o.toString()) 
CONSTRAINT PrDataUnique UNIQUE (entryid, path), 
FOREIGN KEY(entryid) REFERENCES PrEntries(entryid) ON DELETE CASCADE ON UPDATE CASCADE 
); 

CREATE TABLE IF NOT EXISTS PrTracks (
trackid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
trackname VARCHAR(64) NOT NULL UNIQUE,      # Track name 
worldid INTEGER NOT NULL,         # ID of world track belongs    to 
    CONSTRAINT TracksUnique UNIQUE (trackid, worldid), 
FOREIGN KEY(worldid) REFERENCES PrWorlds(worldid) ON DELETE CASCADE ON UPDATE CASCADE 
); 

CREATE TABLE IF NOT EXISTS PrTrackGroups (
trackgroupid INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, 
trackid INTEGER NOT NULL,           # ID of track 
gid INTEGER NOT NULL,            # ID of group in  track 
groupOrder INTEGER NOT NULL,          # Denotes position of  the group in the track 
CONSTRAINT TrackGroupsUnique UNIQUE (trackid, gid), 
FOREIGN KEY(trackid) REFERENCES PrTracks(trackid) ON DELETE CASCADE ON UPDATE CASCADE, 
FOREIGN KEY(gid) REFERENCES PrEntries(entryid) ON DELETE CASCADE ON UPDATE CASCADE 
); 

그것은 phpMyAdmin을 최신 버전에서 실행이 오류가 발생합니다 :

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FOREIGN KEY(worldid) REFERENCES PrWorlds(worldid) ON DELETE CASCADE ON UPDATE CA' at line 8 

yum을 통해 항상 최신 MySQL 서버 실행을, PHP 버전은 PHP-MySQL은 물론 yum을 통해 추가로 5.3이다.
이 모든 것은 CentOS 5.5 64bit에서 실행됩니다.

+0

오류가 ENTRYINDEX''이다. –

+0

7 번 줄에 ENTRYINDEX이란 무엇입니까? – patapizza

답변

3

ENTRYINDEX을 제거하고 AUTOINCREMENTAUTO_INCREMENT으로 변경하십시오.

올바른 코드는이 될 것입니다 :

CREATE TABLE IF NOT EXISTS PrWorlds (     # World table 
worldid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, 
worldname VARCHAR(32) NOT NULL UNIQUE     # Name of world 
); 

CREATE TABLE IF NOT EXISTS PrEntries (     # User/Group table 
entryid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, 
name VARCHAR(32) NOT NULL,        # Name of user/group 
worldid INTEGER NOT NULL,        # ID of the world the  user/group belongs to 
type TINYINT NOT NULL,         # Type denotes the entry type.  0 for a user, 1 for a group 
CONSTRAINT NameWorld UNIQUE (name, worldid, type), 
FOREIGN KEY(worldid) REFERENCES PrWorlds(worldid) ON DELETE CASCADE ON UPDATE CASCADE 
); 

CREATE TABLE IF NOT EXISTS PrPermissions (       # Table of  permission nodes 
permid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, 
permstring VARCHAR(64) NOT NULL,          # Permission node 
entryid INTEGER NOT NULL,            # Entry whom this  node belongs to 
CONSTRAINT PrEntryPerm UNIQUE (entryid, permstring), 
FOREIGN KEY(entryid) REFERENCES PrEntries(entryid) ON DELETE CASCADE ON UPDATE CASCADE 
); 


CREATE TABLE IF NOT EXISTS PrInheritance (     # Table of parent-child  relationships 
uinheritid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, 
childid INTEGER NOT NULL,         # Child entry 
parentid INTEGER NOT NULL,         # Parent entry 
parentorder INTEGER NOT NULL,        # Denotes order of  inheritance. 
                  # Groups override other  groups' permissions/data 
                  # below them in the results 
CONSTRAINT PrParent UNIQUE (childid, parentid), 
CONSTRAINT PrOrderedInheritance UNIQUE (childid, parentorder), 
CONSTRAINT PrNoSelfInherit CHECK (childid <> parentid), 
FOREIGN KEY(childid) REFERENCES PrEntries(entryid) ON DELETE CASCADE ON UPDATE CASCADE, 
FOREIGN KEY(parentid) REFERENCES PrEntries(entryid) ON DELETE CASCADE ON UPDATE CASCADE 
); 

CREATE TABLE IF NOT EXISTS PrWorldBase (  # Table of the default groups in that world 
worldid INTEGER NOT NULL, 
defaultid INTEGER,       # Default group 
FOREIGN KEY(worldid) REFERENCES PrWorlds(worldid) ON DELETE CASCADE ON UPDATE CASCADE, 
FOREIGN KEY(defaultid) REFERENCES PrEntries(entryid) ON DELETE CASCADE ON UPDATE CASCADE 
); 

CREATE TABLE IF NOT EXISTS PrData (
dataid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, 
entryid INTEGER NOT NULL ,     # ID entry whom this data node belongs to 
path VARCHAR(64) NOT NULL,     # Path to data node (e.g. "prefix", "build") 
data VARCHAR(64) NOT NULL,     # Data node in string form (o.toString()) 
CONSTRAINT PrDataUnique UNIQUE (entryid, path), 
FOREIGN KEY(entryid) REFERENCES PrEntries(entryid) ON DELETE CASCADE ON UPDATE CASCADE 
); 

CREATE TABLE IF NOT EXISTS PrTracks (
trackid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, 
trackname VARCHAR(64) NOT NULL UNIQUE,      # Track name 
worldid INTEGER NOT NULL,         # ID of world track belongs    to 
    CONSTRAINT TracksUnique UNIQUE (trackid, worldid), 
FOREIGN KEY(worldid) REFERENCES PrWorlds(worldid) ON DELETE CASCADE ON UPDATE CASCADE 
); 

CREATE TABLE IF NOT EXISTS PrTrackGroups (
trackgroupid INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, 
trackid INTEGER NOT NULL,           # ID of track 
gid INTEGER NOT NULL,            # ID of group in  track 
groupOrder INTEGER NOT NULL,          # Denotes position of  the group in the track 
CONSTRAINT TrackGroupsUnique UNIQUE (trackid, gid), 
FOREIGN KEY(trackid) REFERENCES PrTracks(trackid) ON DELETE CASCADE ON UPDATE CASCADE, 
FOREIGN KEY(gid) REFERENCES PrEntries(entryid) ON DELETE CASCADE ON UPDATE CASCADE 
); 
0

데이터베이스의 기본 테이블 유형이 MyISAM 또는 기타 일 수 있습니까? FOREIGN KEYINNODB으로 지원되지만 SQL은 사용할 테이블 유형을 지정하지 않습니다.