求大神找一下錯誤

來源:互聯網
上載者:User
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);

運行之後出現錯誤

[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--------------------------------------------------

找了大半天都沒找到哪裡的錯誤 求大神指點

回複內容:

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);

運行之後出現錯誤

[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--------------------------------------------------

找了大半天都沒找到哪裡的錯誤 求大神指點

最後一個建立表的語句有問題:

CREATE TABLE `imooc_album` (    `id` int(10) auto_increment key,    `pId` not null);

問題在於,沒有指定pId的資料類型,改成下面這樣就沒問題了:

DROP TABLE IF EXISTS `imooc_album`;CREATE TABLE `imooc_album` (    `id` int(10) auto_increment key,    `pId` int(10) not null);
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.