--创建表空间
create tablespace epet_tablespace
datafile 'D:\epet.dbf'
size 5M;
--创建用户
create user epet identified by accp
default tablespace epet_tablespace
temporary tablespace temp;
--授予权限(连接、操作数据库对象)
grant connect,resource to epet;
--创建主人表
create table master(
id number(11) primary key,
lginid nvarchar2(50) not null,
password nvarchar2(20) not null,
status char(1) default 1 not null);
--创建宠物类型
create table pet_type(
id number(11) primary key,
name nvarchar2(50) not null,
status char(1) default 1 not null);
--创建宠物表
create table pet(
id number(11) not null,
master_id number(11) not null,
name nvarchar2(50) not null,
type_id number(11) not null,
health number(11) default 100 not null,
love number(11) default 0 not null,
prop1 nvarchar2(100),
prop2 nvarchar2(100),
prop3 nvarchar2(100),
adopt_time date not null,
status char(1) default 1 not null,
constraint pet_pk primary key(id),
constraint master_fk foreign key(master_id) references master(id),
constraint type_fi foreign key(type_id) references pet_type(id));
--增加注释
comment on table pet is '宠物';
comment on column pet.name is '宠物昵称';
comment on column pet.health is '宠物健康值';
--为主人表创建序列
create sequence sep_master
start with 1
increment by 1
nomaxvalue
cache 10;
--为宠物类型表创建序列
create sequence sep_pet_type
start with 1
increment by 1
nomaxvalue
cache 10;
--为宠物表创建序列
create sequence sep_pet
start with 1
increment by 1
nomaxvalue
cache 10;
--***************添加数据*********************
--向主人表添加数据
insert into master values(sep_master.nextval,'admin','123456',default);
insert into master values(sep_master.nextval,'jbit','bdqn',default);
insert into master values(sep_master.nextval,'cgj','123456','2');
commit;
--向宠物类型表添加数据
insert into pet_type values(sep_pet_type.nextval,'雪娜瑞',default);
insert into pet_type values(sep_pet_type.nextval,'拉多拉布',default);
insert into pet_type values(sep_pet_type.nextval,'Q仔',default);
insert into pet_type values(sep_pet_type.nextval,'Q妹',default);
commit;
--向宠物表添加数据
insert into pet values(sep_pet.nextval,1,'欧欧',1,100,0,'','','',sysdate,default);
insert into pet values(sep_pet.nextval,2,'美美',2,100,0,'','','',sysdate,default);
insert into pet values(sep_pet.nextval,3,'楠楠',3,100,0,'','','',sysdate,default);
insert into pet values(sep_pet.nextval,1,'贝贝',4,100,0,'','','',sysdate,default);
insert into pet values(sep_pet.nextval,2,'亚亚',1,100,0,'','','',sysdate,default);
commit;
--查询表信息
select * from master;
select * from pet;
select * from pet_type;