大头虾,照书敲代码也会错!

来源:互联网 发布:微商城数据安全吗 编辑:程序博客网 时间:2024/05/17 06:55

刚照书敲了下面这段MYSQL语句创建表格,一执行下来出了几个错误:

 

create table customers

 ( customerid int unsigned not null auto_increment primary key,

name char(50) not null,

address char(100) not null,

city char (30) not null );

create table orders

 

( orderid int unsigned not null auto_increment primary key,

 

customerid int unsigned not null,

amount float(6,2),

 

date date not null ); 

 

create table books

 (isbn char(13) not null primary key,

 author char(50),

title char(100),

price float(4,2) );

create table order_items

(oderid int unsigned not null,

 isbn char(13) not null,

quantity tinyint unsigned,

 primary key(orderid,isbn) );

create table book_reviews

(isbn char(13) not null primary key,

review text );

 

1、第一次把“(”敲成“{”了结果系统提示错误:

MySQL 返回:文档

#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 '{ customerid int unsigned not null auto_increment primary key,

name char(50)' at line 3

 

2、修改完上面的错误后,第二次执行系统提示错误:

#1072 - Key column 'orderid' doesn't exist in table

原来敲错列名了,后面两个表更新为下面代码后终于成功创建了:

create table order_items
(
orderid int unsigned not null,
isbn char(13) not null,
quantity tinyint unsigned,
primary key(orderid, isbn)
);

create table book_reviews
(
isbn char(13) not null primary key,
review text
);