2012-08-17 114 views
3

我想在Filemaker-> MySQL轉換腳本中使用此查詢。表創建步驟直接從phpMyAdmin導出中獲取,並添加到DROP語句中。創建表的MySQL語法錯誤

DROP TABLE IF EXISTS artifacts; 

CREATE TABLE IF NOT EXISTS `artifacts` 
    ( 
    `aid`      INT(11) UNSIGNED NOT NULL auto_increment, 
    `accession number`   TEXT NOT NULL, 
    `name`      TEXT NOT NULL, 
    `period 1`     TEXT NOT NULL, 
    `period 3 date`    TEXT NOT NULL, 
    `visual description`  TEXT NOT NULL, 
    `religion 1`    TEXT NOT NULL, 
    `dimen 1 number`   DECIMAL(10, 2) NOT NULL, 
    `dimen 2 number`   DECIMAL(10, 2) NOT NULL, 
    `dimen 3 number`   DECIMAL(10, 2) NOT NULL, 
    `dimen 1 type`    TEXT NOT NULL, 
    `dimen 2 type`    TEXT NOT NULL, 
    `dimen 3 type`    TEXT NOT NULL, 
    `materials 2`    TEXT NOT NULL, 
    `manufacturing processes 2` TEXT NOT NULL, 
    `weight`     INT(11) NOT NULL, 
    `measuring remarks`   TEXT NOT NULL, 
    `munsell color information` TEXT NOT NULL, 
    `reproduction`    TEXT NOT NULL, 
    `reproduction notes`  TEXT NOT NULL, 
    `published description`  TEXT NOT NULL, 
    `scholarly notes`   TEXT NOT NULL, 
    `bibliography`    TEXT NOT NULL, 
    `comparanda`    TEXT NOT NULL, 
    `exhibit label`    TEXT NOT NULL, 
    `artist`     TEXT NOT NULL, 
    `spurlock loc 3`   TEXT NOT NULL, 
    `archaeological data`  TEXT NOT NULL, 
    `credit line`    TEXT NOT NULL, 
    `provenance`    TEXT NOT NULL, 
    `museum dedication`   TEXT NOT NULL, 
    `spurlock status`   TEXT NOT NULL, 
    `public description`  TEXT NOT NULL, 
    `working set 5 wb`   TEXT NOT NULL, 
    `image source`    TEXT NOT NULL, 
    `cm mec ma`     TEXT NOT NULL, 
    `webprivate`    TEXT NOT NULL, 
    `spurlock loc 2`   TEXT NOT NULL, 
    `hiresimagecheck`   TEXT NOT NULL, 
    PRIMARY KEY (`aid`), 
    FULLTEXT KEY `name` (`name`), 
    FULLTEXT KEY `accession number` (`accession number`, `name`, `period 1`, 
    `visual description`, `materials 2`, `published description`, `artist`, 
    `credit line`), 
    FULLTEXT KEY `accession number_2` (`accession number`), 
    FULLTEXT KEY `visual description` (`visual description`), 
    FULLTEXT KEY `published description` (`published description`) 
) 
engine=myisam 
DEFAULT charset=latin1 
auto_increment=1; 

DROP TABLE IF EXISTS culture; 

CREATE TABLE IF NOT EXISTS `culture` 
    ( 
    `cid`  INT(10) UNSIGNED NOT NULL auto_increment, 
    `culture` VARCHAR(255) NOT NULL, 
    PRIMARY KEY (`cid`), 
    UNIQUE KEY `culture` (`culture`) 
) 
engine=myisam 
DEFAULT charset=latin1 
auto_increment=1; 

DROP TABLE IF EXISTS geocity; 

CREATE TABLE IF NOT EXISTS `geocity` 
    ( 
    `gid` INT(10) UNSIGNED NOT NULL auto_increment, 
    `city` VARCHAR(255) NOT NULL, 
    PRIMARY KEY (`gid`), 
    UNIQUE KEY `city` (`city`) 
) 
engine=myisam 
DEFAULT charset=latin1 
auto_increment=1; 

DROP TABLE IF EXISTS geocontinent; 

CREATE TABLE IF NOT EXISTS `geocontinent` 
    ( 
    `gid`  INT(10) UNSIGNED NOT NULL auto_increment, 
    `continent` VARCHAR(255) NOT NULL, 
    PRIMARY KEY (`gid`), 
    UNIQUE KEY `continent` (`continent`) 
) 
engine=myisam 
DEFAULT charset=latin1 
auto_increment=1; 

DROP TABLE IF EXISTS geocountry; 

CREATE TABLE IF NOT EXISTS `geocountry` 
    ( 
    `gid`  INT(10) UNSIGNED NOT NULL auto_increment, 
    `country` VARCHAR(255) NOT NULL, 
    PRIMARY KEY (`gid`), 
    UNIQUE KEY `country` (`country`) 
) 
engine=myisam 
DEFAULT charset=latin1 
auto_increment=1; 

DROP TABLE IF EXISTS geolocality; 

CREATE TABLE IF NOT EXISTS `geolocality` 
    ( 
    `gid`  INT(10) UNSIGNED NOT NULL auto_increment, 
    `locality` VARCHAR(255) NOT NULL, 
    PRIMARY KEY (`gid`), 
    UNIQUE KEY `locality` (`locality`) 
) 
engine=myisam 
DEFAULT charset=latin1 
auto_increment=1; 

DROP TABLE IF EXISTS georegion; 

CREATE TABLE IF NOT EXISTS `georegion` 
    ( 
    `gid` INT(10) UNSIGNED NOT NULL auto_increment, 
    `region` VARCHAR(255) NOT NULL, 
    PRIMARY KEY (`gid`), 
    UNIQUE KEY `region` (`region`) 
) 
engine=myisam 
DEFAULT charset=latin1 
auto_increment=1; 

DROP TABLE IF EXISTS nomcategory; 

CREATE TABLE IF NOT EXISTS `nomcategory` 
    ( 
    `nid`  INT(10) UNSIGNED NOT NULL auto_increment, 
    `category` VARCHAR(255) NOT NULL, 
    PRIMARY KEY (`nid`), 
    UNIQUE KEY `category` (`category`) 
) 
engine=myisam 
DEFAULT charset=latin1 
auto_increment=1; 

DROP TABLE IF EXISTS nomclassification; 

CREATE TABLE IF NOT EXISTS `nomclassification` 
    ( 
    `nid`   INT(10) UNSIGNED NOT NULL auto_increment, 
    `classification` VARCHAR(255) NOT NULL, 
    PRIMARY KEY (`nid`), 
    UNIQUE KEY `classification` (`classification`) 
) 
engine=myisam 
DEFAULT charset=latin1 
auto_increment=1; 

DROP TABLE IF EXISTS nomsubclassification; 

CREATE TABLE IF NOT EXISTS `nomsubclassification` 
    ( 
    `nid`    INT(10) UNSIGNED NOT NULL auto_increment, 
    `subclassification` VARCHAR(255) NOT NULL, 
    PRIMARY KEY (`nid`), 
    UNIQUE KEY `subclassification` (`subclassification`) 
) 
engine=myisam 
DEFAULT charset=latin1 
auto_increment=1;

然而,當我試圖執行這個查詢,我得到:

MySQL Error: 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 'CREATE TABLE IF NOT EXISTS `artifacts` 
    ( 
    `aid`      IN' at line 3 

語法一切看起來對我好,任何人都可以發現這個錯誤嗎?我使用的唯一SQL格式化程序報告沒有錯誤。

+0

我習慣NUMBER不是INT和VARCHAR不是文本 - 與尺寸... – Randy 2012-08-17 16:30:38

+0

我想在我的MySQL服務器腳本,它工作正常。 – Tchoupi 2012-08-17 16:33:02

+1

你的腳本工作正常。 [*在這裏@SQLFiddle *](http://sqlfiddle.com/#!2/07352/1) – 2012-08-17 16:36:13

回答

6

你的腳本工作正常。問題是,要麼你正在執行它(客戶端會期望通過查詢而不是整個腳本查詢)的方式,或者你已經改變了你的分隔符到別的東西比;

DELIMITER ; 
+1

啊,你是對的。 PHP的'mysql_query()'不支持多個查詢。謝謝。 – 2012-08-17 16:40:37

0
  1. 請問您的用戶名具有創建表的權限?
  2. 您是否指出要使用哪個數據庫?我通常做

    USE databasename; 
    
    CREATE TABLE tablename (
    name_id INT UNSIGNED NOT NULL AUTO_INCREMENT, 
    (etc....) 
    );