oracle创建表

     三个表item,product,orders,分别有主键 外键。另外创建了sequence让各表主键都自增,如:create itemid_sequence increment by 1 start by 1。以下是在PL/SQL下建立表后 自动生成的SQL。。。

 

-- Create table
create table ITEM
(
  TYPEID VARCHAR2(14) not null,
  TYPE   VARCHAR2(10)
)
tablespace USERS
  pctfree 10
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table
comment on table ITEM
  is '产品分类';
-- Add comments to the columns
comment on column ITEM.TYPEID
  is '分类号';
comment on column ITEM.TYPE
  is '分类名';
-- Create/Recreate primary, unique and foreign key constraints
alter table ITEM
  add constraint PK_ITEM primary key (TYPEID)
  using index
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );

 

——————————————

-- Create table
create table PRODUCT
(
  PRODUCTID VARCHAR2(14) not null,
  TITLE     VARCHAR2(10),
  TYPEID    VARCHAR2(14) not null,
  INFO      VARCHAR2(50),
  PRICE     VARCHAR2(10)
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table
comment on table PRODUCT
  is '产品';
-- Create/Recreate primary, unique and foreign key constraints
alter table PRODUCT
  add constraint PK_PRODUCT primary key (PRODUCTID)
  using index
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
alter table PRODUCT
  add constraint FK_PRODUCT foreign key (TYPEID)
  references ITEM (TYPEID) on delete cascade;

 

——————————————

-- Create table
create table ORDERS
(
  ORDERID   VARCHAR2(14) not null,
  NAME      VARCHAR2(10),
  ADDRESS   VARCHAR2(20),
  TEL       VARCHAR2(16),
  EMAIL     VARCHAR2(30),
  BTIME     DATE,
  PRODUCTID VARCHAR2(14) not null
)
tablespace SYSTEM
  pctfree 10
  pctused 40
  initrans 1
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
-- Add comments to the table
comment on table ORDERS
  is '订单';
-- Create/Recreate primary, unique and foreign key constraints
alter table ORDERS
  add constraint PK_ORDERS primary key (ORDERID)
  using index
  tablespace SYSTEM
  pctfree 10
  initrans 2
  maxtrans 255
  storage
  (
    initial 64K
    minextents 1
    maxextents unlimited
  );
alter table ORDERS
  add constraint FK_ORDERS foreign key (PRODUCTID)
  references PRODUCT (PRODUCTID) on delete cascade;


 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值