---
title: "CREATE TYPE"
url: "https://docs.yugabyte.com/stable/api/ycql/ddl_create_type/"
---

# CREATE TYPE

Use the CREATE TYPE statement to create a new user-defined data type in a keyspace.

## Synopsis

Use the `CREATE TYPE` statement to create a new user-defined data type in a keyspace. It defines the name of the user-defined type and the names and data types for its fields.

## Syntax

### Diagram

CREATETYPEIFNOTEXISTS[type\_name](/stable/api/ycql/grammar_diagrams#type-name)(,[field\_name](/stable/api/ycql/grammar_diagrams#field-name)[field\_type](/stable/api/ycql/grammar_diagrams#field-type))

### Grammar

```ebnf
create_type ::= CREATE TYPE [ IF NOT EXISTS ] type_name
                    (field_name field_type [ ',' field_name field_type ...]);
```

Where

- `type_name` and `field_name` are identifiers (`type_name` may be qualified with a keyspace name).
- `field_type` is a data type.

## Semantics

- An error is raised if the specified `type_name` already exists in the associated keyspace unless the `IF NOT EXISTS` option is used.
- Each `field_name` must each be unique (a type cannot have two fields of the same name).
- Each `field_type` must be either a [non-parametric type](/stable/api/ycql/#data-types "non-parametric type") or a [frozen type](/stable/api/ycql/type_frozen "frozen type").

## Examples

Collection types must be frozen to be used inside a user-defined type.

```sql
ycqlsh:example> CREATE TYPE person(first_name TEXT, last_name TEXT, emails FROZEN<LIST<TEXT>>);
```

```sql
ycqlsh:example> DESCRIBE TYPE person;
```

```output
CREATE TYPE example.person (
    first_name text,
    last_name text,
    emails frozen<list<text>>
);
```

```sql
ycqlsh:example> CREATE TABLE employees(employee_id INT PRIMARY KEY, employee person);
```

```sql
ycqlsh:example> INSERT INTO employees(employee_id, employee)
                   VALUES (1, {first_name : 'John', last_name : 'Doe', emails : ['jdoe@example.com']});
```

```sql
ycqlsh:example> SELECT * FROM employees;
```

```output
 employee_id | employee
-------------+---------------------------------------------------------------------------
           1 | {first_name: 'John', last_name: 'Doe', emails: ['john.doe@yugabyte.com']}
```

## See also

- [CREATE TABLE](/stable/api/ycql/ddl_create_table "CREATE TABLE")
- [DROP TYPE](/stable/api/ycql/ddl_drop_type "DROP TYPE")
