> For the complete documentation index, see [llms.txt](https://docs.schemajs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.schemajs.com/reference-guides/schemajs-global/column.md).

# Column

The `Column` class in **SchemaJS** defines the structure and properties of a column within a table. Each column has a name, data type, optional default value, and additional properties such as whether it is required or acts as a primary key. The `Column` class provides several methods for customizing the behavior and constraints of the column, making it flexible and powerful for defining database schemas.

## Constructor

```typescript
new Column(name: string, dataType?: DataTypes)
```

## string

Sets the column's data type to `String`.

```typescript
column.string()
```

## boolean

Sets the column's data type to `Boolean`.

```typescript
column.boolean()
```

## require

Whether the column is required to exist during insertion.

```typescript
column.require(data: boolean)
```

## withComment

Adds a comment or description to the column for documentation purposes.

```typescript
column.withComment(comment: string)
```

## withDefaultValue

Sets a default value for the column. The value is validated to ensure it matches the column's data type.

```typescript
column.withDefaultValue(val: any)
```

{% hint style="info" %}
The value is validated to ensure it matches the column's data type.
{% endhint %}
