mysql与oracle

来源:互联网 发布:js单选框点击事件 编辑:程序博客网 时间:2024/05/02 00:54
----oracle创建主键自增的写法
create table users(


userId   number primary key ,           --oracle写法,不支持identity自增
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(60) not null,           --用户地址
postcode char(6) not null,              --邮编
grade  int   default 1             --用户的级别


)


create sequence ue increment by 1 start with 1    


-----mysql创建主键自增的表的写法
create table goods(


goodsId  int primary key AUTO_INCREMENT ,       
goodsName varchar(40) ,                 
goodsIntro varchar(1000) ,              
goodsPrice  float,                      
goodsNum   int,                        
publisher  varchar(50),               
photo varchar(60),                       
type varchar(50 )      
          
)




insert  into goods values( ge.nextval,'西游.降魔篇','这是一部口碑极好地电影','79.9','1','香港邵氏电影出品','01.jpg','香港电影');    -----oracle写法


insert  into goods values( null,'西游.降魔篇','这是一部口碑极好地电影','79.9','1','香港邵氏电影出品','01.jpg','香港电影');                   --------mysql写法




constraint 外键名字 foreign key  references 外键表(外键字段)


----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 -- 总价格
  )






----sqlserve2000
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
create table orderDetail(
ordesIid bigint  references orders(ordersId),
    ---ordesIid bigint constraint fk_order_id references orders(ordersId)这种写法报错
goodsId bigint references goods(goodsId),
nums int not null
)