create table and data for w3school

create table persons(
id int,
lastname varchar2(10),
firstname varchar2(10),
address varchar2(100),
city varchar2(20)
);
//插入的关键字是values,而不是value
insert into persons values(1,'Adams','John','Oxford Street','London');
insert into persons values(2,'Bush','George','Fifth Avenue','New York');
insert into persons values(3,'Carter','Thomas','Changan Street','Beijing');
insert into persons values(4,'Obama','Barack','Pennsylvania Avenue','Washington');
//修改persons的id为主键
alter table persons 
add constraint pk_con primary key(id);

//foreign key的引用要指向主键
create table orders(
id int,
orderNo number(9),
id_p int,
constraint foreignkey_con foreign key(id_p) references persons(id)
);
//删除order表的限制关系
alter table drop constraint foreignkey_con;

insert to orders values(1,77895,3);
insert to orders values(2,44678,3);
insert to orders values(3,22456,1);
insert to orders values(4,24562,1);
insert to orders values(5,34764,65);

create table employees_china(
e_id number(9),
e_name varchar2(50)
);

create table employees_USA(
e_id number(9),
e_name varchar2(50)
);
insert into employees_china values(01,'Zhang,Hua');
insert into employees_china values(02,'Wang,Wei');
insert into employees_china values(03,'Carter,Thomas');
insert into employees_china values(04,'Yang,Ming');

insert into employees_usa values(01,'Adams,John');
insert into employees_usa values(02,'Bush,George');
insert into employees_usa values(03,'Carter,Thomas');
insert into employees_usa values(04,'Gates,Bill');

 

你可能感兴趣的:(oracle)