Name

CREATE-TABLE — Create a database table.Function

Syntax

      create-table name description &key database constraints transactions => 

Arguments and Values

name

The name of the table as a string, symbol or SQL expression.

database

A database object which defaults to *default-database*.

description

A list.

constraints

A string, a list of strings or NIL.

transactions

A Boolean. The default value is T.

Description

Creates a table called name, which may be a string, symbol or SQL table identifier, in database which defaults to *default-database*. description is a list whose elements are lists containing the attribute names, types, and other constraints such as not-null or primary-key for each column in the table.

constraints is a string representing an SQL table constraint expression or a list of such strings.

With MySQL databases, if transactions is T an InnoDB table is created which supports transactions.

Examples

(create-table [foo]
              '(([id] integer)
                ([height] float)
                ([name] (string 24))
                ([comments] text)))
=> 
(table-exists-p [foo]) 
=> T 

(create-table [foo] '(([bar] integer :not-null :unique :primary-key) 
                      ([baz] string :not-null :unique)))
=> 
(table-exists-p [foo])
=> T

(create-table [foo] '(([bar] integer :not-null) ([baz] string :not-null))
              :constraints '("UNIQUE (bar,baz)" "PRIMARY KEY (bar)"))
=> 
(table-exists-p [foo])
=> T
      

Side Effects

A table is created in database.

Affected by

*default-database*

Exceptional Situations

An error is signalled if name is not a string, symbol or SQL expression. An error of type sql-database-data-error is signalled if a relation called name already exists.

See Also

drop-table
list-tables
table-exists-p

Notes

The constraints and transactions keyword arguments to create-table are CLSQL extensions. The transactions keyword argument is for compatibility with MySQL databases.