您的位置:首页 > 数据库 > MySQL

简单的SQL Server语句转换为Mysql。

2015-06-13 23:03 531 查看
以下为自己学习中遇到的问题,为了以免忘记做个笔记。

用户表:

create table users
(
userid bigint primary key AUTO_INCREMENT,
username varchar(30) not null unique,
truename varchar(30) not null,
passwd varchar(30) not null,
email varchar (40) not null,
phone varchar(20) not null,
address varchar(30) not null,
postcode char(6) not null,
grade int default 1

);


商品表:

create table goods
(
goodsId SMALLINT UNSIGNED primary key AUTO_INCREMENT,
goodsName varchar(40) not null,
goodsIntro varchar(500) not null,
goodsPrice float not null,
goodsNum int not null,
publisher varchar(40) not null,
photo varchar(40) not null,
type varchar(10)
);


商品订单表:

create table orders(

ordersId bigint auto_increment primary key , -- 订单号
userId   bigint references users(userid), -- 哪个用户订的
orderDate datetime , -- 下订单的时间
orderDate timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
//设置默认时间值
//如果是在navicat下操作的话,设置字段的类型为timestamp,默认值写上CURRENT_TIMESTAMP
payMode varchar(20) default '货到付款', -- 付款的方式
isPayed bit , -- (0,表示还没有付款 1:表示已经付款了)
totalPrice float not null -- 总价格
);


订单细节表

CREATE TABLE orderDetail(
orderIid BIGINT,
FOREIGN KEY (orderIid) REFERENCES orders (ordersId) ,
goodsId SMALLINT UNSIGNED,//unsigned也一定要写上
FOREIGN KEY (goodsId) REFERENCES goods (goodsid),
num int not null
);


FOREIGN KEY:外键约束

REFERENCES:参照对象。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sql