首页 > 后端开发 > php教程 > 求大神找一下错误

求大神找一下错误

WBOY
发布: 2016-06-06 20:29:27
原创
1153 人浏览过

<code>CREATE DATABASE IF NOT EXISTS `shopImooc1`;
USE `shopImooc1`;
DROP TABLE IF EXISTS `imooc_admin`;
CREATE TABLE `imooc_admin` (
    `id` int(10) auto_increment  key,
    `username` varchar(20) not null unique,
    `password` char(32) not null,
    `email` varchar(50)
);

DROP TABLE IF EXISTS `imooc_cate`;
CREATE TABLE `imooc_cate` (
    `id` smallint(10) auto_increment key,
    `cName` varchar(20) unique
);

DROP TABLE IF EXISTS `imooc_pro`;
CREATE TABLE `imooc_pro` (
    `id` int(10) unique auto_increment key,
    `pNmae` varchar(50) not null unique,
    `pSn` varchar(50) not null,
    `cPrice` decimal(10,2) not null,
    `iPrice` decimal(10,2) not null,
    `pDesc` text,
    `pImg` varchar(50) not null,
    `pubImg` int not null,
    `isShows` tinyint(1) default 1,
    `isHot` tinyint(1) default 0,
    `cId` smallint not null
);


DROP TABLE IF EXISTS `imooc_user`;
CREATE TABLE `imooc_user` (
    `id` int(10) auto_increment  key,
    `username` varchar(20) not null unique,
    `password` varchar(32) not null,
    `face` varchar(50) not null,
    `regTime` int not null
);



DROP TABLE IF EXISTS `imooc_album`;
CREATE TABLE `imooc_album` (
    `id` int(10) auto_increment key,
    `pId` not null
);
</code>
登录后复制
登录后复制

运行之后出现错误

<code>[Err] 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 'not null,
)' at line 3
[Err] CREATE DATABASE IF NOT EXISTS `shopImooc1`;
USE `shopImooc1`;
DROP TABLE IF EXISTS `imooc_admin`;
CREATE TABLE `imooc_admin` (
    `id` int(10) auto_increment  key,
    `username` varchar(20) not null unique,
    `password` char(32) not null,
    `email` varchar(50)
);

DROP TABLE IF EXISTS `imooc_cate`;
CREATE TABLE `imooc_cate` (
    `id` smallint(10) auto_increment key,
    `cName` varchar(20) unique
);

DROP TABLE IF EXISTS `imooc_pro`;
CREATE TABLE `imooc_pro` (
    `id` int(10) unique auto_increment key,
    `pNmae` varchar(50) not null unique,
    `pSn` varchar(50) not null,
    `cPrice` decimal(10,2) not null,
    `iPrice` decimal(10,2) not null,
    `pDesc` text,
    `pImg` varchar(50) not null,
    `pubImg` int not null,
    `isShows` tinyint(1) default 1,
    `isHot` tinyint(1) default 0,
    `cId` smallint not null
);


DROP TABLE IF EXISTS `imooc_user`;
CREATE TABLE `imooc_user` (
    `id` int(10) auto_increment  key,
    `username` varchar(20) not null unique,
    `password` varchar(32) not null,
    `face` varchar(50) not null,
    `regTime` int not null
);



DROP TABLE IF EXISTS `imooc_album`;
CREATE TABLE `imooc_album` (
    `id` int(10) auto_increment key,
    `pId` not null,
);
[Msg] Finished - Unsuccessfully
--------------------------------------------------
</code>
登录后复制
登录后复制

找了大半天都没找到哪里的错误 求大神指点

回复内容:

<code>CREATE DATABASE IF NOT EXISTS `shopImooc1`;
USE `shopImooc1`;
DROP TABLE IF EXISTS `imooc_admin`;
CREATE TABLE `imooc_admin` (
    `id` int(10) auto_increment  key,
    `username` varchar(20) not null unique,
    `password` char(32) not null,
    `email` varchar(50)
);

DROP TABLE IF EXISTS `imooc_cate`;
CREATE TABLE `imooc_cate` (
    `id` smallint(10) auto_increment key,
    `cName` varchar(20) unique
);

DROP TABLE IF EXISTS `imooc_pro`;
CREATE TABLE `imooc_pro` (
    `id` int(10) unique auto_increment key,
    `pNmae` varchar(50) not null unique,
    `pSn` varchar(50) not null,
    `cPrice` decimal(10,2) not null,
    `iPrice` decimal(10,2) not null,
    `pDesc` text,
    `pImg` varchar(50) not null,
    `pubImg` int not null,
    `isShows` tinyint(1) default 1,
    `isHot` tinyint(1) default 0,
    `cId` smallint not null
);


DROP TABLE IF EXISTS `imooc_user`;
CREATE TABLE `imooc_user` (
    `id` int(10) auto_increment  key,
    `username` varchar(20) not null unique,
    `password` varchar(32) not null,
    `face` varchar(50) not null,
    `regTime` int not null
);



DROP TABLE IF EXISTS `imooc_album`;
CREATE TABLE `imooc_album` (
    `id` int(10) auto_increment key,
    `pId` not null
);
</code>
登录后复制
登录后复制

运行之后出现错误

<code>[Err] 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 'not null,
)' at line 3
[Err] CREATE DATABASE IF NOT EXISTS `shopImooc1`;
USE `shopImooc1`;
DROP TABLE IF EXISTS `imooc_admin`;
CREATE TABLE `imooc_admin` (
    `id` int(10) auto_increment  key,
    `username` varchar(20) not null unique,
    `password` char(32) not null,
    `email` varchar(50)
);

DROP TABLE IF EXISTS `imooc_cate`;
CREATE TABLE `imooc_cate` (
    `id` smallint(10) auto_increment key,
    `cName` varchar(20) unique
);

DROP TABLE IF EXISTS `imooc_pro`;
CREATE TABLE `imooc_pro` (
    `id` int(10) unique auto_increment key,
    `pNmae` varchar(50) not null unique,
    `pSn` varchar(50) not null,
    `cPrice` decimal(10,2) not null,
    `iPrice` decimal(10,2) not null,
    `pDesc` text,
    `pImg` varchar(50) not null,
    `pubImg` int not null,
    `isShows` tinyint(1) default 1,
    `isHot` tinyint(1) default 0,
    `cId` smallint not null
);


DROP TABLE IF EXISTS `imooc_user`;
CREATE TABLE `imooc_user` (
    `id` int(10) auto_increment  key,
    `username` varchar(20) not null unique,
    `password` varchar(32) not null,
    `face` varchar(50) not null,
    `regTime` int not null
);



DROP TABLE IF EXISTS `imooc_album`;
CREATE TABLE `imooc_album` (
    `id` int(10) auto_increment key,
    `pId` not null,
);
[Msg] Finished - Unsuccessfully
--------------------------------------------------
</code>
登录后复制
登录后复制

找了大半天都没找到哪里的错误 求大神指点

最后一个创建表的语句有问题:

<code class="sql">CREATE TABLE `imooc_album` (
    `id` int(10) auto_increment key,
    `pId` not null
);</code>
登录后复制

问题在于,没有指定pId的数据类型,改成下面这样就没问题了:

<code class="sql">DROP TABLE IF EXISTS `imooc_album`;
CREATE TABLE `imooc_album` (
    `id` int(10) auto_increment key,
    `pId` int(10) not null
);</code>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板