---
title: "Define a Schema - GSQL 101"
description: "GSQL 101 tutorial to define a schema."
component: "gsql-ref"
version: "4.3"
module: "tutorials"
html_url: "/gsql-ref/4.3/tutorials/gsql-101/define-a-schema"
canonical_url: "https://www.tigergraph.com/docs/gsql-ref/4.3/tutorials/gsql-101/define-a-schema"
markdown_url: "https://www.tigergraph.com/docs/gsql-ref/4.3/tutorials/gsql-101/define-a-schema.md"
---

[View as HTML](https://www.tigergraph.com/docs/gsql-ref/4.3/tutorials/gsql-101/define-a-schema)

# Define a Schema - GSQL 101

This section of the tutorial uses a simple example to walk you through the steps to define a schema in GSQL.

The first step in creating a GSQL graph is to define its schema. GSQL provides a set of Data Definition Language (DDL) commands, similar to SQL DDL commands, to model vertex types, edge types and a graph.

For this tutorial, we will work mostly in the GSQL shell, in interactive mode. A few commands will be from a Linux shell.

## Create a vertex type

Use `CREATE VERTEX ` to define a vertex type named `Person`. Here, `PRIMARY_ID` is required: each person must have a unique identifier. The rest is the optional list of attributes which characterize each person vertex, in the format `attribute_name data_type, attribute_name data_type, …​`

GSQL command

```gsql
BEGIN
CREATE VERTEX Person (
    PRIMARY_ID name STRING,
    name STRING,
    age INT,
    gender STRING,
    state STRING
)
END
```

> [!NOTE]
> We show GSQL keywords in all caps to highlight them in accordance with the [GSQL Style Guide](https://www.tigergraph.com/docs/gsql-ref/4.3/appendix/gsql-style-guide.md), but they are case-insensitive.

GSQL will confirm the creation of the vertex type.

GSQL shell

```gsql
GSQL > CREATE VERTEX Person (PRIMARY_ID name STRING, name STRING, age INT, gender STRING, state STRING)
Successfully created vertex types: [Person].
```

You can create as many vertex types as you need.

**Maximum Size**

A vertex primary key has a length limit of 16384 bytes. The size of a vertex, including all of its attributes, cannot exceed 10 megabytes.

## Create an edge type

Next, use the `CREATE …​ EDGE` command to create an edge type named `Friendship`. The keyword `UNDIRECTED` indicates this edge is a bidirectional edge, meaning that information can flow starting from either vertex. If you'd rather have a unidirectional connection where information flows only from the `FROM` vertex, use the `DIRECTED` keyword in place of `UNDIRECTED`. Here, `FROM` and `TO` are required to specify which two vertex types the edge type connects. An individual edge is specified by giving the primary\_ids of its source (`FROM`) vertex and target (`TO`) vertex. These are followed by an optional list of attributes, just as in the vertex definition.

GSQL command

```gsql
CREATE UNDIRECTED EDGE Friendship (FROM Person, TO Person, connect_day DATETIME)
```

GSQL will confirm the creation of the edge type.

GSQL shell

```gsql
GSQL > CREATE UNDIRECTED EDGE Friendship (FROM Person, TO Person, connect_day DATETIME)
Successfully created edge types: [Friendship].
GSQL >
```

You can create as many edge types as you need.

## Create a graph

Next, use the `CREATE GRAPH` command to create a graph named `Social`. Here, we just list the vertex types and edge types that we want to include in this graph.

GSQL command

```gsql
CREATE GRAPH Social (Person, Friendship)
```

GSQL will confirm the creation of the first graph after several seconds, during which it pushes the catalog information to all services, such as the Graph Storage Engine (GSE), Graph Processing Engine (GPE) and TigerGraph's REST server - RESTPP.

GSQL shell

```gsql
GSQL > CREATE GRAPH Social (Person, Friendship)
Stopping GPE GSE RESTPP
Successfully stopped GPE GSE RESTPP in 16.554 seconds
Starting GPE GSE RESTPP
Successfully started GPE GSE RESTPP in 0.119 seconds
The graph Social is created.
```

At this point, we have created a `Person` vertex type, a `Friendship` edge type, and a `Social` graph that includes them.

You've now built your first graph schema! Take a look at the catalog by typing the `ls` command in the GSQL shell.

GSQL shell

```gsql
GSQL > ls
---- Graph Social
Vertex Types:
  - VERTEX Person(PRIMARY_ID name STRING, name STRING, age INT, gender STRING, state STRING) WITH STATS="OUTDEGREE_BY_EDGETYPE"
Edge Types:
  - UNDIRECTED EDGE Friendship(FROM Person, TO Person, connect_day DATETIME)

Graphs:
  - Graph Social(Person:v, Friendship:e)
Jobs:
Queries:
```
