有个表格,在创建表格的时候已经指定字段不能为空,可是调用储存过程中插入数据的时候字段为空时居然没有报错,也没有抛出异常,是不是要自己去验证数据是否为空或者是定义异常机制.

解决方案 »

  1.   

    检查sql的模式mysql> select @@sql_mode;
    +----------------------------------------------------------------+
    | @@sql_mode                                                     |
    +----------------------------------------------------------------+
    | STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
    +----------------------------------------------------------------+
    1 row in set
    mysql> 如果没有开启严格模式是不会报错的
      

  2.   

    搜索了一下,结果是这样的,我用的是5.1的版本.
    +----------------------------------------------------------------+
    | @@sql_mode |
    +----------------------------------------------------------------+
    | NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION 
    +----------------------------------------------------------------+
    现在应该怎么改才会满足要求
      

  3.   

    show create table 提供一下你的建表语句。
      

  4.   

    create table orderitem{
    orderitemid bigint(20) uisigned not null auto_increment,
    pname varchar(32) not null,
    price double not null,
    pid bigint(20) unsigned not null,
    number int(10) unsigend not null,
    oid varchar(36) not null,
    primary key(orderitemid ),
    key pname(pname),
    key oid(oid),
    key pid(pid)
    )ENGINE=InnoDB auto_increment=10 default charset=utf8
      

  5.   

    mysql> create table orderitem{
        -> orderitemid bigint(20) uisigned not null auto_increment,
        -> pname varchar(32) not null,
        -> price double not null,
        -> pid bigint(20) unsigned not null,
        -> number int(10) unsigend not null,
        -> oid varchar(36) not null,
        -> primary key(orderitemid ),
        -> key pname(pname),
        -> key oid(oid),
        -> key pid(pid)
        -> )ENGINE=InnoDB auto_increment=10 default charset=utf8;
    ERROR 1064 (42000): 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 '{
    orderitemid bigint(20) uisigned not null auto_increment,
    pname varchar(32) not' at line 1
    mysql>
    楼主就是用这段代码建表的???
    建议你原来复制你的 show create table orderitem; 然后什么都不要改。同时把你的insert 语句也可以提供一下。
      

  6.   


    修改mysql配置文件my.ini里的sql-mode参数,改成STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION 
      

  7.   

    create table 'orderitem'(
    'orderitemid' bigint(20) uisigned not null auto_increment,
    'pname' varchar(32) not null,
    'price' double not null,
    'pid' bigint(20) unsigned not null,
    'number' int(10) unsigend not null,
    'oid' varchar(36) not null,
    primary key('orderitemid' ),
    key 'pname'('pname'),
    key 'oid'('oid'),
    key 'pid'('pid')
    )ENGINE=InnoDB auto_increment=10 default charset=utf8
    没改 上面有个括号打错了,显示就是这样的.有些大写改成小写应该没问题的
      

  8.   

    建议原样复制。
    mysql> create table 'orderitem'(
        -> 'orderitemid' bigint(20) uisigned not null auto_increment,
        -> 'pname' varchar(32) not null,
        -> 'price' double not null,
        -> 'pid' bigint(20) unsigned not null,
        -> 'number' int(10) unsigend not null,
        -> 'oid' varchar(36) not null,
        -> primary key('orderitemid' ),
        -> key 'pname'('pname'),
        -> key 'oid'('oid'),
        -> key 'pid'('pid')
        -> )ENGINE=InnoDB auto_increment=10 default charset=utf8;
    ERROR 1064 (42000): 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 ''orde
    ritem'(
    'orderitemid' bigint(20) uisigned not null auto_increment,
    'pname' ' at line 1
    mysql>
      

  9.   

    |orderitem | CREATE TABLE 'orderitem'(
    'orderitemid' bigint(20) uisigned NOT NULL AUTO_INCREMENT,
    'pname' varchar(32) not null,
    'price' double not null,
    'pid' bigint(20) unsigned not null,
    'number' int(10) unsigend not null,
    'oid' varchar(36) not null,
    PRIMARY KEY('orderitemid' ),
    KEY 'pname'('pname'),
    KEY 'oid'('oid'),
    KEY 'pid'('pid')
    )ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 |
    现在是一模一样了,不知道开头和结尾的|拿来做什么,我创建表的时候用的index被改成key了。
      

  10.   

    insert into会报空,但是调用储存过程就不会报空,insert语句和平常的一样,没有区别.
    ACMAIN_CHM:
    有没有碰过这样的情况,感觉怪怪的.
      

  11.   

    我创建表的时候也没有用单引号,同时也没有AUTO_INCREMENT=10 我是设置 AUTO_INCREMENT=0的
      

  12.   

    如果真的是原样复制的,那真是奇怪了, 注意红色部分。 (真的是原样复制的吗???)|orderitem | CREATE TABLE 'orderitem'(
    'orderitemid' bigint(20) uisigned NOT NULL AUTO_INCREMENT,
    'pname' varchar(32) not null,
    'price' double not null,
    'pid' bigint(20) unsigned not null,
    'number' int(10) unsigend not null,
    'oid' varchar(36) not null,
    PRIMARY KEY('orderitemid' ),
    KEY 'pname'('pname'),
    KEY 'oid'('oid'),
    KEY 'pid'('pid')
    )ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 |
      

  13.   

    给出你的create table 语句 insert into 语句,这样别人可以模拟你的问题,从而发现问题所在。否则大家只能是猜测。
      

  14.   

    我不知道怎么复制,所以操下来了,那个是手操的错误,改成unsigned其他应该没错了
      

  15.   

     马虎害死人啊。另外提醒一下你的所有的 ' 也不对!
     CREATE TABLE 'orderitem'(
    'orderitemid' bigint(20) uisigned NOT NULL AUTO_INCREMENT,
    'pname' varchar(32) n....
      

  16.   

    没有你说的问题。
    建议你描述一下你是实现情况。mysql> CREATE TABLE `orderitem`(
        -> `orderitemid` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
        -> `pname` varchar(32) not null,
        -> `price` double not null,
        -> `pid` bigint(20) unsigned not null,
        -> `number` int(10) unsigned not null,
        -> `oid` varchar(36) not null,
        -> PRIMARY KEY(`orderitemid` ),
        -> KEY `pname`(`pname`),
        -> KEY `oid`(`oid`),
        -> KEY `pid`(`pid`)
        -> )ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
    Query OK, 0 rows affected (0.11 sec)mysql> insert into orderitem values (null,null,null,null,null,null);
    ERROR 1048 (23000): Column 'pname' cannot be null
    mysql>