Skip to content

Commit 37768b1

Browse files
author
Anh Le
committedDec 9, 2021
Add sql db sample and playground sql
1 parent 0c0da3b commit 37768b1

File tree

5 files changed

+3293
-0
lines changed

5 files changed

+3293
-0
lines changed
 

‎assets/sampledb/ot_create_user.sql

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--------------------------------------------------------------------------------------
2+
-- Name : OT (Oracle Tutorial) Sample Database
3+
-- Link : http://www.oracletutorial.com/oracle-sample-database/
4+
-- Version : 1.0
5+
-- Last Updated: July-28-2017
6+
-- Copyright : Copyright © 2017 by www.oracletutorial.com. All Rights Reserved.
7+
-- Notice : Use this sample database for the educational purpose only.
8+
-- Credit the site oracletutorial.com explitly in your materials that
9+
-- use this sample database.
10+
--------------------------------------------------------------------------------------
11+
--------------------------------------------------------------------
12+
-- execute the following statements to create a user name OT and
13+
-- grant priviledges
14+
--------------------------------------------------------------------
15+
16+
-- create new user
17+
CREATE USER OT IDENTIFIED BY yourpassword;
18+
19+
-- grant priviledges
20+
GRANT CONNECT, RESOURCE, DBA TO OT;

‎assets/sampledb/ot_data.sql

+3,057
Large diffs are not rendered by default.

‎assets/sampledb/ot_drop.sql

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--------------------------------------------------------------------------------------
2+
-- Name : OT (Oracle Tutorial) Sample Database
3+
-- Link : http://www.oracletutorial.com/oracle-sample-database/
4+
-- Version : 1.0
5+
-- Last Updated: July-28-2017
6+
-- Copyright : Copyright © 2017 by www.oracletutorial.com. All Rights Reserved.
7+
-- Notice : Use this sample database for the educational purpose only.
8+
-- Credit the site oracletutorial.com explitly in your materials that
9+
-- use this sample database.
10+
--------------------------------------------------------------------------------------
11+
DROP TABLE ot.order_items;
12+
DROP TABLE ot.orders;
13+
DROP TABLE ot.inventories;
14+
DROP TABLE ot.products;
15+
DROP TABLE ot.product_categories;
16+
DROP TABLE ot.warehouses;
17+
DROP TABLE ot.employees;
18+
DROP TABLE ot.contacts;
19+
DROP TABLE ot.customers;
20+
DROP TABLE ot.locations;
21+
DROP TABLE ot.countries;
22+
DROP TABLE ot.regions;

‎assets/sampledb/ot_schema.sql

+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
--------------------------------------------------------------------------------------
2+
-- Name : OT (Oracle Tutorial) Sample Database
3+
-- Link : http://www.oracletutorial.com/oracle-sample-database/
4+
-- Version : 1.0
5+
-- Last Updated: July-28-2017
6+
-- Copyright : Copyright © 2017 by www.oracletutorial.com. All Rights Reserved.
7+
-- Notice : Use this sample database for the educational purpose only.
8+
-- Credit the site oracletutorial.com explitly in your materials that
9+
-- use this sample database.
10+
--------------------------------------------------------------------------------------
11+
12+
13+
---------------------------------------------------------------------------
14+
-- execute the following statements to create tables
15+
---------------------------------------------------------------------------
16+
-- regions
17+
CREATE TABLE regions
18+
(
19+
region_id NUMBER GENERATED BY DEFAULT AS IDENTITY
20+
START WITH 5 PRIMARY KEY,
21+
region_name VARCHAR2( 50 ) NOT NULL
22+
);
23+
-- countries table
24+
CREATE TABLE countries
25+
(
26+
country_id CHAR( 2 ) PRIMARY KEY ,
27+
country_name VARCHAR2( 40 ) NOT NULL,
28+
region_id NUMBER , -- fk
29+
CONSTRAINT fk_countries_regions FOREIGN KEY( region_id )
30+
REFERENCES regions( region_id )
31+
ON DELETE CASCADE
32+
);
33+
34+
-- location
35+
CREATE TABLE locations
36+
(
37+
location_id NUMBER GENERATED BY DEFAULT AS IDENTITY START WITH 24
38+
PRIMARY KEY ,
39+
address VARCHAR2( 255 ) NOT NULL,
40+
postal_code VARCHAR2( 20 ) ,
41+
city VARCHAR2( 50 ) ,
42+
state VARCHAR2( 50 ) ,
43+
country_id CHAR( 2 ) , -- fk
44+
CONSTRAINT fk_locations_countries
45+
FOREIGN KEY( country_id )
46+
REFERENCES countries( country_id )
47+
ON DELETE CASCADE
48+
);
49+
-- warehouses
50+
CREATE TABLE warehouses
51+
(
52+
warehouse_id NUMBER
53+
GENERATED BY DEFAULT AS IDENTITY START WITH 10
54+
PRIMARY KEY,
55+
warehouse_name VARCHAR( 255 ) ,
56+
location_id NUMBER( 12, 0 ), -- fk
57+
CONSTRAINT fk_warehouses_locations
58+
FOREIGN KEY( location_id )
59+
REFERENCES locations( location_id )
60+
ON DELETE CASCADE
61+
);
62+
-- employees
63+
CREATE TABLE employees
64+
(
65+
employee_id NUMBER
66+
GENERATED BY DEFAULT AS IDENTITY START WITH 108
67+
PRIMARY KEY,
68+
first_name VARCHAR( 255 ) NOT NULL,
69+
last_name VARCHAR( 255 ) NOT NULL,
70+
email VARCHAR( 255 ) NOT NULL,
71+
phone VARCHAR( 50 ) NOT NULL ,
72+
hire_date DATE NOT NULL ,
73+
manager_id NUMBER( 12, 0 ) , -- fk
74+
job_title VARCHAR( 255 ) NOT NULL,
75+
CONSTRAINT fk_employees_manager
76+
FOREIGN KEY( manager_id )
77+
REFERENCES employees( employee_id )
78+
ON DELETE CASCADE
79+
);
80+
-- product category
81+
CREATE TABLE product_categories
82+
(
83+
category_id NUMBER
84+
GENERATED BY DEFAULT AS IDENTITY START WITH 6
85+
PRIMARY KEY,
86+
category_name VARCHAR2( 255 ) NOT NULL
87+
);
88+
89+
-- products table
90+
CREATE TABLE products
91+
(
92+
product_id NUMBER
93+
GENERATED BY DEFAULT AS IDENTITY START WITH 289
94+
PRIMARY KEY,
95+
product_name VARCHAR2( 255 ) NOT NULL,
96+
description VARCHAR2( 2000 ) ,
97+
standard_cost NUMBER( 9, 2 ) ,
98+
list_price NUMBER( 9, 2 ) ,
99+
category_id NUMBER NOT NULL ,
100+
CONSTRAINT fk_products_categories
101+
FOREIGN KEY( category_id )
102+
REFERENCES product_categories( category_id )
103+
ON DELETE CASCADE
104+
);
105+
-- customers
106+
CREATE TABLE customers
107+
(
108+
customer_id NUMBER
109+
GENERATED BY DEFAULT AS IDENTITY START WITH 320
110+
PRIMARY KEY,
111+
name VARCHAR2( 255 ) NOT NULL,
112+
address VARCHAR2( 255 ) ,
113+
website VARCHAR2( 255 ) ,
114+
credit_limit NUMBER( 8, 2 )
115+
);
116+
-- contacts
117+
CREATE TABLE contacts
118+
(
119+
contact_id NUMBER
120+
GENERATED BY DEFAULT AS IDENTITY START WITH 320
121+
PRIMARY KEY,
122+
first_name VARCHAR2( 255 ) NOT NULL,
123+
last_name VARCHAR2( 255 ) NOT NULL,
124+
email VARCHAR2( 255 ) NOT NULL,
125+
phone VARCHAR2( 20 ) ,
126+
customer_id NUMBER ,
127+
CONSTRAINT fk_contacts_customers
128+
FOREIGN KEY( customer_id )
129+
REFERENCES customers( customer_id )
130+
ON DELETE CASCADE
131+
);
132+
-- orders table
133+
CREATE TABLE orders
134+
(
135+
order_id NUMBER
136+
GENERATED BY DEFAULT AS IDENTITY START WITH 106
137+
PRIMARY KEY,
138+
customer_id NUMBER( 6, 0 ) NOT NULL, -- fk
139+
status VARCHAR( 20 ) NOT NULL ,
140+
salesman_id NUMBER( 6, 0 ) , -- fk
141+
order_date DATE NOT NULL ,
142+
CONSTRAINT fk_orders_customers
143+
FOREIGN KEY( customer_id )
144+
REFERENCES customers( customer_id )
145+
ON DELETE CASCADE,
146+
CONSTRAINT fk_orders_employees
147+
FOREIGN KEY( salesman_id )
148+
REFERENCES employees( employee_id )
149+
ON DELETE SET NULL
150+
);
151+
-- order items
152+
CREATE TABLE order_items
153+
(
154+
order_id NUMBER( 12, 0 ) , -- fk
155+
item_id NUMBER( 12, 0 ) ,
156+
product_id NUMBER( 12, 0 ) NOT NULL , -- fk
157+
quantity NUMBER( 8, 2 ) NOT NULL ,
158+
unit_price NUMBER( 8, 2 ) NOT NULL ,
159+
CONSTRAINT pk_order_items
160+
PRIMARY KEY( order_id, item_id ),
161+
CONSTRAINT fk_order_items_products
162+
FOREIGN KEY( product_id )
163+
REFERENCES products( product_id )
164+
ON DELETE CASCADE,
165+
CONSTRAINT fk_order_items_orders
166+
FOREIGN KEY( order_id )
167+
REFERENCES orders( order_id )
168+
ON DELETE CASCADE
169+
);
170+
-- inventories
171+
CREATE TABLE inventories
172+
(
173+
product_id NUMBER( 12, 0 ) , -- fk
174+
warehouse_id NUMBER( 12, 0 ) , -- fk
175+
quantity NUMBER( 8, 0 ) NOT NULL,
176+
CONSTRAINT pk_inventories
177+
PRIMARY KEY( product_id, warehouse_id ),
178+
CONSTRAINT fk_inventories_products
179+
FOREIGN KEY( product_id )
180+
REFERENCES products( product_id )
181+
ON DELETE CASCADE,
182+
CONSTRAINT fk_inventories_warehouses
183+
FOREIGN KEY( warehouse_id )
184+
REFERENCES warehouses( warehouse_id )
185+
ON DELETE CASCADE
186+
);

‎cmd/playground/playground.sql

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Display all tables
2+
SELECT DISTINCT OBJECT_NAME
3+
FROM USER_OBJECTS
4+
WHERE OBJECT_TYPE = 'TABLE';
5+
6+
-- Simple query
7+
SELECT * FROM EMPLOYEES;
8+
SELECT COUNT(*) FROM EMPLOYEES;

0 commit comments

Comments
 (0)
Please sign in to comment.