三个表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;