日期:2014-05-16  浏览次数:20721 次

sql server 转成mysql,怎么转
我在sql server 是这样的:
create table orders(

ordersId bigint primary key identity(1,1),--订单号
userId bigint constraint fk_client_id references users(userid),--哪个用户订的
orderDate datetime default getdate(),--下订单的时间
payMode varchar(20)check (payMode in('货到付款','支付宝付款')) default '货到付款',--付款的方式
isPayed bit check ( isPayed in (0 ,1)),--(0,表示还没有付款 1:表示已经付款了)
totalPrice float not null--总价格
)

create table orderDetail(

ordesIid bigint constraint fk_order_id references orders(ordersId),--订单号(并是一个外键) 指向orders表的主键
goodsId bigint constraint fk_shangpin_id references goods(goodsId),--商品号(并是一个外键) 指向goods表的主键
nums int not null--数量
)
 

  我想问下我在mysql要怎么写才能实现同样效果的表,请各位高手指教下,谢谢!

------解决方案--------------------
1 . MySQL 中没有 identity(1,1), 用 auto_increment
2. MySQL 中不支持CHECK。
3. MySQL 语法略有不同。建议你可以参考一下手册中的语法和例子。

SQL code
mysql> create table orders(
    ->
    ->  ordersId bigint auto_increment primary key , -- 订单号
    ->  userId   bigint references users(userid), -- 哪个用户订的
    ->  orderDate datetime , -- 下订单的时间
    ->  payMode varchar(20) default '货到付款', -- 付款的方式
    ->  isPayed bit , -- (0,表示还没有付款 1:表示已经付款了)
    ->  totalPrice float not null -- 总价格
    -> )
    -> ;
Query OK, 0 rows affected (0.11 sec)

mysql>