Skip to content

Commit 67169fb

Browse files
Add SQL equivalent schema
1 parent b250377 commit 67169fb

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

core-concepts/modules/ROOT/pages/typeql/sql-vs-typeql.adoc

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,36 @@ This difference means that some SQL concepts map directly and others have differ
1111

1212
== Schema setup
1313

14-
For the examples here, we can use a simple TypeQL schema:
14+
Let's use a small schema for people, companies, and employments.
15+
16+
If this schema were implemented in a typical SQL database, you'd define two main tables (`person` and `company`) with attributes for each, and a join table (`employment`) to represent the relationship between people and companies.
17+
18+
Each `person` has a name, email, and age. Each `company` has a name. The `employment` table links people to companies using foreign keys.
19+
20+
Example SQL table definitions:
21+
22+
[sql]
23+
----
24+
CREATE TABLE person (
25+
id SERIAL PRIMARY KEY,
26+
name VARCHAR,
27+
email VARCHAR,
28+
age INTEGER
29+
);
30+
31+
CREATE TABLE company (
32+
id SERIAL PRIMARY KEY,
33+
name VARCHAR
34+
);
35+
36+
CREATE TABLE employment (
37+
id SERIAL PRIMARY KEY,
38+
employee_id INTEGER REFERENCES person(id),
39+
employer_id INTEGER REFERENCES company(id)
40+
);
41+
----
42+
43+
Here's the equivalent TypeQL schema:
1544

1645
[,typeql]
1746
----
@@ -25,7 +54,7 @@ define
2554
entity company, owns name, plays employment:employer;
2655
----
2756

28-
With the following data:
57+
If you're testing as you go - here's some sample data you can use to populate your TypeDB database!
2958
[,typeql]
3059
----
3160
#!test[write, commit]

0 commit comments

Comments
 (0)