### Exposed 0.56.0 Help

# Table types

In Exposed, the `Table` class is the core abstraction for defining database tables. This class provides methods to define various column types, constraints, and other table-specific properties.

`Table` is located in the org.jetbrains.exposed.sql package of the exposed-core module.

The following example defines a table with an auto-incrementing integer `id` column and a string `name` column:

import org.jetbrains.exposed.sql.Table object Cities : Table("cities") { val id = integer("id").autoIncrement() val name = varchar("name", 50) }
CREATE TABLE IF NOT EXISTS CITIES (ID INT AUTO_INCREMENT NOT NULL, "name" VARCHAR(50) NOT NULL)

For more information on defining and configuring tables in Exposed, see Working with tables.

While `Table` is the foundational class for defining tables in DSL, you can also use the `IdTable` subclasses from the DAO API for convenience. For example, to provide an auto-incrementing `id` column of type `Int`, you can use the `IntIdTable` subtype:

object StarWarsFilms : IntIdTable() { val sequelId = integer("sequel_id").uniqueIndex() val name = varchar("name", 50) val director = varchar("director", 50) }

It is important to note that the `id` column in this case is of type `Column<EntityID<Int>>`. The `EntityID` wrapper ensures that the `id` values are handled consistently across the DSL and DAO APIs.

To access the `id` column value, you need to use the `.value` property:

val idValue = StarWarsFilms.id.value

For more information on `IdTable`, see the DAO documentation.

Last modified: 30 October 2024