oracle資料庫從入門到精通之三

2021-09-08 12:19:48 字數 3950 閱讀 2678

綜合案例

ddl&dml

有乙個商品資料庫

1.資料表的建立    ddl

先編寫資料庫指令碼

--刪除資料表

drop table purcase purge;

drop table product purge;

drop table customer purge;

--建立資料表

create table product(

product_id varchar2(5),

product_name varchar2(30) not null,

unit_price number,

category varchar2(50),

provider varchar2(50),

constraint pk_product_id primary key(product_id),

constraint ck_unit_price check(unit_price>0)

);create table customer(

customer_id varchar2(5),

customer_name varchar2(30) not null,

location varchar2(50),

constraint pk_customer_id primary key(customer_id)

);create table purcase(

customer_id varchar2(5),

product_id varchar2(5),

quantity number,

constraint fk_customer_id foreign key(customer_id) references customer(customer_id) on delete cascade,

constraint fk_product_id foreign key(product_id) references product(product_id) on delete cascade,

constraint ck_quantity check(quantity)

);--增加測試資料

--增加產品資訊

insert into product(product_id,product_name,unit_price,category,provider)

values('m01','jjs',8.00,'yg','bj');

insert into product(product_id,product_name,unit_price,category,provider)

values('m02','glj',6.50,'yg','glj');

insert into product(product_id,product_name,unit_price,category,provider)

values('m03','jl',5.00,'yg','lhlh');

insert into product(product_id,product_name,unit_price,category,provider)

values('m04','sfj',3.00,'xz','bj');

insert into product(product_id,product_name,unit_price,category,provider)

values('m05','xsl',5.00,'xz','lhlh');

insert into product(product_id,product_name,unit_price,category,provider)

values('m06','dp',2.50,'xyf','nas');

insert into product(product_id,product_name,unit_price,category,provider)

values('m07','zh',3.50,'yg','lhlh');

insert into product(product_id,product_name,unit_price,category,provider)

values('m08','tz',3.00,'xyf','bj');

insert into product(product_id,product_name,unit_price,category,provider)

values('m09','bl',4.00,'xyf','bj');

--增加客戶資訊

insert into customer(customer_id,customer_name,location)

values('c01','dennis','hd');

insert into customer(customer_id,customer_name,location)

values('c02','john','cy');

insert into customer(customer_id,customer_name,location)

values('c03','tom','dc');

insert into customer(customer_id,customer_name,location)

values('c04','jenny','dc');

insert into customer(customer_id,customer_name,location)

values('c05','rick','xc');

--增加購買記錄

insert into purcase(customer_id,product_id,quantity)

values('c01','m01',3);

insert into purcase(customer_id,product_id,quantity)

values('c01','m05',2);

insert into purcase(customer_id,product_id,quantity)

values('c01','m08',2);

insert into purcase(customer_id,product_id,quantity)

values('c02','m02',5);

insert into purcase(customer_id,product_id,quantity)

values('c02','m06',4);

insert into purcase(customer_id,product_id,quantity)

values('c03','m01',1);

insert into purcase(customer_id,product_id,quantity)

values('c03','m05',1);

insert into purcase(customer_id,product_id,quantity)

values('c03','m06',3);

insert into purcase(customer_id,product_id,quantity)

values('c03','m08',1);

insert into purcase(customer_id,product_id,quantity)

values('c04','m03',7);

insert into purcase(customer_id,product_id,quantity)

values('c04','m04',3);

insert into purcase(customer_id,product_id,quantity)

values('c05','m06',2);

insert into purcase(customer_id,product_id,quantity)

values('c05','m07',8);

commit;

PostgreSQL資料庫從入門到精通

課程介紹 postgresql被譽為 世界上功能最強大的開源資料庫 是以加州大學伯克利分校計算機系開發的postgres 4.2為基礎的物件關係型資料庫管理系統。postgresql支援大部分 sql標準並且提供了許多其他現代特性 複雜查詢 外來鍵 觸發器 檢視 事務完整性 mvcc。同樣,post...

PostgreSQL資料庫從入門到精通

阿里雲大學課程 postgresql資料庫從入門到精通 課程介紹 postgresql被譽為 世界上功能最強大的開源資料庫 是以加州大學伯克利分校計算機系開發的postgres 4.2為基礎的物件關係型資料庫管理系統。postgresql支援大部分 sql標準並且提供了許多其他現代特性 複雜查詢 外...

Oracle從入門到精通教程 資料庫實戰精講

本套教程講解了oracle資料庫基礎 搭建oracle資料庫環境 sql plus命令列工具的使用 標準sql oracle資料核心 表空間 oracle資料庫常用物件,資料庫效能優化,資料的匯出與匯入,索引,檢視,連線查詢,子查詢,sequence,資料庫設計三正規化等。oracle databa...