为什么我的SQL创建会出错?

时间:2013-02-13 18:54:06

标签: mysql sql

以下SQL语句有什么问题:

create table teamstats (name varchar(10) not null,pos varchar(3) not null,ab numeric(3) not null,hits numberic(4) not null,walks varchar(5) not null,singles varchar(7) not null,doubles varchar7) not null,triples varchar(7) not null,hr numeric(2) not null,so varchar(2) not null);

我得到了:

  

错误1064(42000):您的SQL语法有错误;检查   手册,对应右边的MySQL服务器版本   在'numberic(4)not null附近使用的语法,walk varchar(5)not nul   l,singles varchar(7)not null,doubl'在第1行

4 个答案:

答案 0 :(得分:2)

错字#1

 doubles varchar7)

应该是

 doubles varchar(7)

错字#2

numberic

应该是

numeric

答案 1 :(得分:2)

SQL中有两个错误:

  1. 命中numberic(4)not null => numberic不是有效的数据类型

  2. double varchar7)not null =>你忘了在varchar中打开括号

  3. 这是正确的语法:

    create table teamstats
    (
        name varchar(10) not null,
        pos varchar(3) not null,
        ab numeric(3) not null,
        hits numeric(4) not null,
        walks varchar(5) not null,
        singles varchar(7) not null,
        doubles varchar(7) not null,
        triples varchar(7) not null,
        hr numeric(2) not null,
        so varchar(2) not null
    );
    

    这是SQL小提琴:http://sqlfiddle.com/#!2/261351

答案 2 :(得分:1)

可能会将numberic更改为numeric

答案 3 :(得分:1)

numeric拼错为numberic;这可以防止MySQL将其检测为数据类型,并且不知道如何继续。您还忘记了双打栏中的左括号:

doubles varchar(7)