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

以下为自己学习中遇到的问题,为了以免忘记做个笔记。
用户表:

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:参照对象。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值