forked from oracle-livelabs/database
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'oracle-livelabs:main' into main
- Loading branch information
Showing
21 changed files
with
726 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Introduction | ||
|
||
Welcome to the "Database Tools" section of this workshop. In the following two labs, you will learn about two different tools that you can use to access the Oracle Database. We will cover both Database Actions (AKA SQL Developer Web) and the new SQL Developer VS Code Extension. These two labs will focus on what they are and how to set them up. | ||
|
||
### **SQL Developer Web** | ||
SQL Developer Web provides a browser-based interface to manage your Oracle Database without requiring additional installations. It supports running queries, managing database objects, and visualizing data models directly through Oracle Database Actions. It’s a straightforward tool designed for quick access and efficient database management. | ||
|
||
### **SQL Developer on VS Code | ||
For those who live in VS Code, the SQL Developer extension integrates Oracle Database management directly into your favorite editor. It combines the elegance of Oracle’s SQL tools with the flexibility of a lightweight coding environment. Writing and running queries, exploring database objects, or debugging PL/SQL—all without leaving the editor—makes this extension a dream for developers who want everything in one place. Plus, with almost 200k installs (since I last checked) it’s as simple to set up as it is to use. | ||
|
||
## Learn More | ||
|
||
* [About SQL Developer Web](https://docs.oracle.com/en/database/oracle/sql-developer-web/20.3/sdweb/about-sdw.html) | ||
* [SQL Developer for VS Code](https://www.oracle.com/database/sqldeveloper/vscode/) | ||
|
||
## Acknowledgements | ||
* **Author** - Killian Lynch, Database Product Management | ||
* **Contributors**: | ||
* **Last Updated By/Date** - Killian Lynch, December 2024 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,37 +91,63 @@ This lab is just a short overview of the functionality introduced with Property | |
``` | ||
<copy> | ||
drop table if exists people cascade CONSTRAINTS; | ||
drop table if exists relationship cascade CONSTRAINTS; | ||
CREATE TABLE people ( | ||
p_id NUMBER PRIMARY KEY, | ||
name VARCHAR2(50) | ||
); | ||
INSERT INTO people (p_id, name) VALUES | ||
(1, 'Alice'), | ||
(2, 'Bob'), | ||
(3, 'Carol'), | ||
(4, 'Dave'), | ||
(5, 'Eve'); | ||
CREATE TABLE relationship ( | ||
r_id NUMBER PRIMARY KEY, | ||
DROP TABLE if exists customer_relationships CASCADE CONSTRAINTS; | ||
DROP TABLE if exists customers CASCADE CONSTRAINTS; | ||
CREATE TABLE CUSTOMERS | ||
( | ||
CUSTOMER_ID NUMBER , | ||
FIRST_NAME VARCHAR2 (100) , | ||
LAST_NAME VARCHAR2 (100) , | ||
EMAIL VARCHAR2 (255) NOT NULL , | ||
SIGNUP_DATE DATE DEFAULT SYSDATE , | ||
HAS_SUB BOOLEAN , | ||
DOB DATE , | ||
ADDRESS VARCHAR2 (200) , | ||
ZIP VARCHAR2 (10) , | ||
PHONE_NUMBER VARCHAR2 (20) , | ||
CREDIT_CARD VARCHAR2 (20) | ||
) ; | ||
INSERT INTO customers (customer_id, first_name, last_name, email, signup_date, has_sub, dob, address, zip, phone_number, credit_card) | ||
VALUES | ||
(1, 'John', 'Doe', '[email protected]', SYSDATE, TRUE, NULL, NULL, NULL, NULL, NULL), | ||
(2, 'Jane', 'Smith', '[email protected]', SYSDATE, TRUE, NULL, NULL, NULL, NULL, NULL), | ||
(3, 'Alice', 'Johnson', '[email protected]', SYSDATE, TRUE, NULL, NULL, NULL, NULL, NULL), | ||
(4, 'Bob', 'Brown', '[email protected]', SYSDATE, TRUE, NULL, NULL, NULL, NULL, NULL), | ||
(5, 'Charlie', 'Davis', '[email protected]', SYSDATE, TRUE, NULL, NULL, NULL, NULL, NULL), | ||
(6, 'David', 'Wilson', '[email protected]', SYSDATE, TRUE, TO_DATE('1985-08-15', 'YYYY-MM-DD'), '123 Elm Street', '90210', '555-1234', '4111111111111111'), | ||
(7, 'Jim', 'Brown', '[email protected]', SYSDATE, TRUE, TO_DATE('1988-01-01', 'YYYY-MM-DD'), '456 Maple Street', '12345', NULL, NULL), | ||
(8, 'Suzy', 'Brown', '[email protected]', SYSDATE, TRUE, TO_DATE('1990-01-01', 'YYYY-MM-DD'), '123 Maple Street', '12345', '555-1234', '4111111111111111'); | ||
CREATE TABLE if not exists customer_relationships( | ||
id NUMBER GENERATED ALWAYS as IDENTITY(START with 1 INCREMENT by 1) not null constraint rel_pk primary key, | ||
source_id NUMBER, | ||
target_id NUMBER, | ||
relationship VARCHAR2(50), | ||
CONSTRAINT connections_people_1_fk FOREIGN KEY (source_id) REFERENCES people (p_id), | ||
CONSTRAINT connections_people_2_fk FOREIGN KEY (target_id) REFERENCES people (p_id) | ||
); | ||
INSERT INTO relationship (r_id, source_id, target_id, relationship) | ||
VALUES | ||
(1, 1, 2, 'friend'), | ||
(2, 2, 3, 'colleague'), | ||
(3, 3, 4, 'neighbor'), | ||
(4, 4, 1, 'sibling'), | ||
(5, 1, 3, 'mentor'); | ||
relationship VARCHAR2(100)); | ||
INSERT INTO customer_relationships (SOURCE_ID, TARGET_ID, RELATIONSHIP) | ||
VALUES | ||
(8, 7, 'Married'), | ||
(7, 8, 'Married'), | ||
(7, 4, 'Brother'), | ||
(4, 7, 'Brother'), | ||
(1, 2, 'Friend'), | ||
(3, 5, 'Colleague'), | ||
(6, 4, 'Neighbor'), | ||
(7, 6, 'Friend'), | ||
(6, 7, 'Friend'), | ||
(7, 3, 'Friend'), | ||
(3, 7, 'Friend'), | ||
(7, 1, 'Friend'), | ||
(1, 7, 'Friend'); | ||
</copy> | ||
``` | ||
|
@@ -136,38 +162,36 @@ This lab is just a short overview of the functionality introduced with Property | |
The property graphs are stored as metadata inside the database meaning they don't store the actual data. Rather, the data is still stored in the underlying objects and we use the SQL/PQG syntax to interact with the property graphs. | ||
"Why not do this in SQL?" Short answer is, you can. However, it may not be simple. Modeling graphs inside the database using SQL can be difficult and cumbersome and could require complex SQL code to accurately represent and query all aspects of a graph. | ||
"Why not do this in SQL?" The short answer is, you can. However, it may not be simple. Modeling graphs inside the database using SQL can be difficult and cumbersome and could require complex SQL code to accurately represent and query all aspects of a graph. | ||
This is where property graphs come in. Property graphs make the process of working with interconnected data, like identifying influencers in a social network, predicting trends and customer behavior, discovering relationships based on pattern matching and more by providing a more natural and efficient way to model and query them. Let's take a look at how to create property graphs and query them using the SQL/PGQ extension. | ||
2. We'll first create a property graph that models the relationship between people (our tables created earlier). | ||
2. We'll first create a property graph that models the relationship between customers. | ||
``` | ||
<copy> | ||
drop property graph if exists relationships_pg; | ||
CREATE PROPERTY GRAPH relationships_pg | ||
VERTEX TABLES ( | ||
people | ||
KEY (p_id) | ||
LABEL person | ||
PROPERTIES ALL COLUMNS | ||
) | ||
EDGE TABLES ( | ||
relationship | ||
KEY (r_id) | ||
SOURCE KEY (source_id) REFERENCES people (p_id) | ||
DESTINATION KEY (target_id) REFERENCES people (p_id) | ||
LABEL relationship | ||
PROPERTIES ALL COLUMNS | ||
); | ||
DROP PROPERTY GRAPH IF EXISTS moviestreams_pg; | ||
create property graph moviestreams_pg | ||
vertex tables ( | ||
customers | ||
key(customer_id) | ||
label customer | ||
properties (customer_id, first_name, last_name) | ||
) | ||
edge tables ( | ||
customer_relationships as related | ||
key (id) | ||
source key(source_id) references customers(customer_id) | ||
destination key(target_id) references customers(customer_id) | ||
properties (id, relationship) | ||
) | ||
</copy> | ||
``` | ||
A couple things to point out here: | ||
* Vertex represent our people table | ||
* Vertex represent our customers table | ||
* Edges represent how they are connected (relationship table) | ||
* Our edges table has a source key and destination key, representing the connection between the two people | ||
|
@@ -285,78 +309,56 @@ This lab is just a short overview of the functionality introduced with Property | |
12. In this short lab we've looked at SQL property graphs and SQL/PGQ in Oracle Database 23ai. We've learned how to create property graphs from existing tables, query these graphs to discover relationships, and prepare data for visualization. | ||
## Task 3: Querying Property Graphs with SQL/PGQ | ||
1. Now we can use SQL/PQG to query and work with our property graphs. We'll use the GRAPH_TABLE operator here to display people who are connected to each other. | ||
13. We can clean our environment. | ||
``` | ||
<copy> | ||
SELECT person_1, relationship, person_2 | ||
FROM graph_table (relationships_pg | ||
MATCH | ||
(p1 IS person) -[r IS relationship]-> (p2 IS person) | ||
COLUMNS (p1.name AS person_1, r.relationship, p2.name AS person_2) | ||
); | ||
drop table if exists customer_relationships CASCADE CONSTRAINTS; | ||
drop table if exists customers CASCADE CONSTRAINTS; | ||
drop property graph moviestreams_pg; | ||
</copy> | ||
``` | ||
![use sql/pgq to query the graph](images/im4.png =50%x*) | ||
## Task 4: Clean up | ||
2. We can filter our results like we can in SQL. | ||
1. Sign back in with the **admin** user. | ||
``` | ||
<copy> | ||
SELECT person_1, relationship, person_2 | ||
FROM graph_table (relationships_pg | ||
MATCH | ||
(p1 IS person WHERE p1.name = 'Alice') -[r IS relationship]-> (p2 IS person) | ||
COLUMNS (p1.name AS person_1, r.relationship, p2.name AS person_2) | ||
); | ||
If you've forgotten your password, it can be found by clicking the **View login info** button in the top left of these instruction. Alternatively, you can watch the gif below to find the password. | ||
</copy> | ||
``` | ||
![reset the password](images/pswrd1.gif " ") | ||
2. Now using the password we found above, sign in as the admin user. | ||
![sign into the admin user](images/im25.png " ") | ||
![use sql/pgq to select a person from the graph](images/im5.png " ") | ||
3. Using the hamburger menu in the upper left hand corner of the screen, find and open the SQL Editor | ||
![sign into the admin user](images/im22.png " ") | ||
4. Terminate any active sessions created by the DB23AI user and drop the user. | ||
3. We can also check the metadata about our graph | ||
``` | ||
<copy> | ||
SELECT person_1, relationship, person_2, id_person_1, id_relationship, id_person_2 | ||
FROM graph_table (relationships_pg | ||
MATCH | ||
(p1 IS person) -[r IS relationship]-> (p2 IS person) | ||
COLUMNS (p1.name AS person_1, | ||
p2.name AS person_2, | ||
r.relationship AS relationship, | ||
vertex_id(p1) AS id_person_1, | ||
edge_id(r) AS id_relationship, | ||
vertex_id(p2) AS id_person_2) | ||
); | ||
BEGIN | ||
FOR session IN (SELECT SID, SERIAL# FROM V$SESSION WHERE USERNAME = 'DB23AI') LOOP | ||
EXECUTE IMMEDIATE 'ALTER SYSTEM KILL SESSION ''' || session.SID || ',' || session.SERIAL# || ''' IMMEDIATE'; | ||
END LOOP; | ||
END; | ||
</copy> | ||
``` | ||
![check graph metadata using sql/pgq](images/im6.png " ") | ||
![terminate sessions](images/im21.png " ") | ||
4. In this short lab we've looked at SQL property graphs and SQL/PGQ in Oracle Database 23ai. We've learned how to create property graphs from existing tables, query these graphs to discover relationships, and prepare data for visualization. | ||
5. Now drop the user | ||
This is just a small sample of what you can do with Property Graphs and SQL/PQG in Oracle Database 23ai. For more in depth labs and other graph functionality, brows through the following link | ||
* [Graphs in 23ai](https://livelabs.oracle.com/pls/apex/f?p=133:100:105582422382278::::SEARCH:graph) | ||
5. We can clean our environment. | ||
``` | ||
<copy> | ||
drop table people cascade CONSTRAINTS; | ||
drop table relationship cascade CONSTRAINTS; | ||
drop property graph relationships_pg; | ||
DROP USER DB23AI CASCADE; | ||
</copy> | ||
``` | ||
You may now **proceed to the next lab** | ||
## Learn More | ||
|
@@ -367,4 +369,4 @@ You may now **proceed to the next lab** | |
## Acknowledgements | ||
* **Author** - Killian Lynch, Database Product Management | ||
* **Contributors** - Dom Giles, Distinguished Database Product Manager | ||
* **Last Updated By/Date** - Killian Lynch, April 2024 | ||
* **Last Updated By/Date** - Killian Lynch, December 2024 |
Oops, something went wrong.