# GENERATE CHANGELOG DDL

## Syntax <a href="#synopsis" id="synopsis"></a>

{% code overflow="wrap" %}

```sql
GENERATE CHANGLEOG DDL changelog_name WITH(stream_parameter = value [, ...]);

GENERATE CHANGLEOG DDL changelog_name PRIMARY KEY(pk_name) WITH(stream_parameter = value [, ...]);
```

{% endcode %}

## Description

This command generates a CREATE DDL for CHANGELOG from a given schema or data — for example, [Data Store](/overview/core-concepts/store.md#entity) — that has corresponding [Data Formats (Serialization)](/reference/sql-syntax/data-format-serialization.md#protocol-buffers-and-descriptors). The command specially simplifies creating DDL for complex descriptors.

You can generate DDL if the current role has [`USAGE`](/overview/core-concepts/access-control.md#privilege) privileges on the [Data Store](/overview/core-concepts/store.md).

## Changelog Parameters <a href="#parameters" id="parameters"></a>

| Parameter Name                | Description                                                                                                                                                                                                                       |
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`changelog_name`**          | The name of the new changelog.                                                                                                                                                                                                    |
| **`primary key`**             | <p>If you provide the primary key names they are added to the DDL. Otherwise, this is empty.<br></p><p><strong>Required?</strong> No.</p>                                                                                         |
| **`topic`**                   | <p>Name of the Kafka topic whose assigned data schema you're using (for Protobuf descriptor and Avro schema from SchemaRegistry).<br></p><p><strong>Required?</strong> Yes, for <code>AVRO</code>, <code>PROTOBUF</code></p>      |
| **`value.format`**            | <p>AVRO, PROTOBUF, JSON</p><p><strong>Required?</strong> Yes.</p>                                                                                                                                                                 |
| **`key.format`**              | <p><code>AVRO</code>, <code>PROTOBUF</code>, <code>JSON</code></p><p><strong>Required?</strong> No.</p>                                                                                                                           |
| **`data.json.value.content`** | <p>A string containing one or more JSON objects separated by commas. It serves as a data sample you use to infer the schema of the value field in Kafka.</p><p><strong>Required?</strong> Required only for <code>JSON</code></p> |
| **`data.json.key.content`**   | <p>A string containing one or more JSON objects separated by commas. It serves as a data sample you used to infer the schema of the key in Kafka.</p><p><strong>Required?</strong> Only for <code>JSON</code></p>                 |

## Generating "Create Changelog" DDL examples <a href="#examples" id="examples"></a>

**Generate a "create changelog" ddl for an entity in the current store, which includes a protobuf descriptor.**

{% code overflow="wrap" %}

```sql
GENERATE CHANGELOG DDL myChangelog with('topic'='pageviews_pb', 'value.format'='protobuf', 
'key.format'='protobuf');
```

{% endcode %}

The output would be:

{% code overflow="wrap" %}

```sql
CREATE CHANGELOG myChangelog(
 "viewtime" BIGINT NOT NULL,
  "userid" VARCHAR NOT NULL,
  "pageid" VARCHAR NOT NULL,
  PRIMARY KEY()  
 ) WITH ('key.format'='protobuf', 'key.type'='STRUCT<"userid" VARCHAR>', 'topic'='pageviews_pb', 'value.format'='protobuf');
```

{% endcode %}

**Generate a "create changelog" ddl for an entity in the current store, which includes AVRO in the Confluent Schema Registry.**

{% code overflow="wrap" %}

```sql
GENERATE CHANGELOG DDL myChangelog with('topic'='pageviews_avro', 'value.format'='avro', 
'key.format'='avro');
```

{% endcode %}

The output would be

{% code overflow="wrap" %}

```sql
CREATE CHANGELOG myChangelog(
 "viewtime" BIGINT ,
  "userid" VARCHAR ,
  "pageid" VARCHAR ,
  PRIMARY KEY() 
) WITH ('key.format'='avro', 'key.type'='STRUCT<"userid" VARCHAR>', 'topic'='pageviews_avro', 'value.format'='avro');     
```

{% endcode %}

**Generate a "create changelog" ddl for an entity whose content is JSON.**

{% code overflow="wrap" %}

```sql
GENERATE CHANGELOG DDL myChangelog with ('value.format'='json', 'data.json.value.content'='{"viewtime":1629453600000,"userid":"user_123","pageid":"page_1"},{"viewtime":1629457200000,"userid":"user_456","pageid":"page_2"},{"viewtime":1629460800000,"userid":"user_789","pageid":"page_3"}' );
```

{% endcode %}

The output would be

```sql
CREATE CHANGELOG myChangelog(
 "viewtime" BIGINT,
 "userid" VARCHAR,
 "pageid" VARCHAR,
  PRIMARY KEY() 
) WITH ('value.format'='json');
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.deltastream.io/reference/sql-syntax/command/generate-changelog-ddl.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
