简单的SQL Server语句转换为Mysql。
2015-06-13 23:03
531 查看
以下为自己学习中遇到的问题,为了以免忘记做个笔记。
用户表:
商品表:
商品订单表:
订单细节表
FOREIGN KEY:外键约束
REFERENCES:参照对象。
用户表:
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中的三值逻辑
- SQL Server 作业批量停止
- 结束SQL阻塞的进程
- 动态生成SQL Server视图作业
- SQL Server 语句操纵数据库
- SQL(结构化查询语句)
- oracle sql日期比较
- linux快速部署mysql服务器
- sql 存储过程分页
- 在WINXP系统上安装SQL Server企业版的方法
- 通过批处理调用SQL的方法(osql)
- SQL Server 存储过程的分页
- ASP程序与SQL存储过程结合使用详解
- SQL SERVER编写存储过程小工具
- 防御SQL注入攻击时需要注意的一个问题
- PostgreSQL教程(十九):SQL语言函数
- SQL Server复制需要有实际的服务器名称才能连接到服务器
- SQL Server 2000向SQL Server 2008 R2推送数据图文教程