Skip to main content

SQL Server Schema

function

The function block describes a function in a database schema.

function "positive" {
schema = schema.public
lang = SQL
arg "v" {
type = integer
}
...
}

function attributes

NameRequiredValue
astruestring
depends_onfalse

List of object references

execute_asfalse

The execution context of the function can be one of:

  1. Raw expression defined with sql("expr")
  2. string
inlinefalsebool
langtrue

Function language can be one of:

  1. string
  2. enum (SQL, CRL)
null_callfalse

enum (CALLED, RETURNS_NULL)

returnfalse

Function return type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to type_alias
schematrue

Object reference to schema

schema_boundfalsebool

function blocks

function.arg

function.arg attributes
NameRequiredValue
defaultfalse

Function argument default value can be one of:

  1. bool
  2. string
  3. number
modefalse

Function argument mode can be one of:

  1. string
  2. enum (IN, INOUT, OUT)
readonlyfalsebool
typetrue

Function argument type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to type_alias
  4. Object reference to type_table
function.arg constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

function.return_table

function.return_table blocks

function.return_table.check

function.return_table.check attributes
NameRequiredValue
exprtruestring
function.return_table.check constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

function.return_table.column

function.return_table.column attributes
NameRequiredValue
asfalsestring
collatefalsestring
commentfalsestring
defaultfalse

Column default value can be one of:

  1. bool
  2. string
  3. number
  4. Raw expression defined with sql("expr")
nullfalsebool
typetrue

Column type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to type_alias
function.return_table.column blocks

function.return_table.column.as

function.return_table.column.as attributes
NameRequiredValue
exprtruestring
typefalse

enum (PERSISTED)

function.return_table.column.identity

function.return_table.column.identity attributes
NameRequiredValue
incrementfalseint
seedfalseint
function.return_table.column constraints
ConstraintValue
Requiredtrue
Require Name (e.g., function.return_table.column "name" )true
Mutually exclusive sets[as (attribute), as (block)]

function.return_table.index

function.return_table.index attributes
NameRequiredValue
columnsfalse

Index columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
includefalse

Index included columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
nonclusteredfalsebool
typefalse

Index key type can be one of:

  1. string
  2. enum (COLUMNSTORE, HASH, HEAP, SPATIAL, XML)
uniquefalsebool
wherefalsestring
function.return_table.index blocks

function.return_table.index.on

function.return_table.index.on attributes
NameRequiredValue
columnfalse

Index columns can be one of:

  1. Object reference to column
  2. Object reference to table.column
descfalsebool
exprfalsestring
opsfalse

Index operator class can be one of:

  1. string
  2. Raw expression defined with sql("expr")
function.return_table.index.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Mutually exclusive sets[column, expr]
function.return_table.index constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Mutually exclusive sets[columns, on]
One of required sets[columns, on]

function.return_table.primary_key

function.return_table.primary_key attributes
NameRequiredValue
columnsfalse

Primary key columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
fill_factorfalseint
includefalse

Primary key included columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
nonclusteredfalsebool
typefalse

Index key type can be one of:

  1. string
  2. enum (HASH)
function.return_table.primary_key blocks

function.return_table.primary_key.on

function.return_table.primary_key.on attributes
NameRequiredValue
columntrue

Primary key columns can be one of:

  1. Object reference to column
  2. Object reference to table.column
descfalsebool
function.return_table.primary_key.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
function.return_table.primary_key constraints
ConstraintValue
Requiredfalse
Require Namefalse
Mutually exclusive sets[columns, on]
One of required sets[columns, on]
function.return_table constraints
ConstraintValue
Requiredfalse
Require Name (e.g., function.return_table "name" )true

function constraints

ConstraintValue
Requiredfalse
Require Name (e.g., function "name" )true
Allow Qualifier (e.g., function "schema" "name" )true

procedure

The procedure block describes a procedure in a database schema.

procedure "proc" {
schema = schema.public
lang = SQL
arg "a" {
type = integer
}
...
}

procedure attributes

NameRequiredValue
astruestring
depends_onfalse

List of object references

execute_asfalse

The execution context of the procedure can be one of:

  1. Raw expression defined with sql("expr")
  2. string
langtrue

Procedure language can be one of:

  1. string
  2. enum (SQL, CRL)
schematrue

Object reference to schema

procedure blocks

procedure.arg

procedure.arg attributes
NameRequiredValue
defaultfalse

Procedure argument default value can be one of:

  1. bool
  2. Raw expression defined with sql("expr")
  3. string
  4. number
modefalse

Procedure argument mode can be one of:

  1. string
  2. enum (IN, INOUT, OUT)
readonlyfalsebool
typetrue

Procedure argument type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to type_alias
  4. Object reference to type_table
procedure.arg constraints
ConstraintValue
Requiredfalse
Require Name (e.g., procedure.arg "name" )true

procedure constraints

ConstraintValue
Requiredfalse
Require Name (e.g., procedure "name" )true
Allow Qualifier (e.g., procedure "schema" "name" )true

schema

The schema block describes a database schema.

schema "public" {
...
}

schema attributes

NameRequiredValue
namefalsestring

schema constraints

ConstraintValue
Requiredfalse
Require Name (e.g., schema "name" )true

sequence

The sequence block describes a sequence in a database schema.

sequence "name" {
schema = schema.public
type = int
increment = 3
min_value = 9
}

sequence attributes

NameRequiredValue
cachefalseint
cyclefalsebool
incrementfalseint
max_valuefalseint
min_valuefalseint
schematrue

Object reference to schema

startfalseint
typefalse

Sequence type can be one of:

  1. Schema type
  2. Object reference to type_alias

sequence constraints

ConstraintValue
Requiredfalse
Require Name (e.g., sequence "name" )true
Allow Qualifier (e.g., sequence "schema" "name" )true

table

The table block describes a table in a database schema.

table "users" {
schema = schema.public
column "id" {
type = int
}
...
}

table attributes

NameRequiredValue
commentfalsestring
depends_onfalse

List of object references

memory_optimizedfalsebool
schematrue

Object reference to schema

system_versionedfalsebool

table blocks

table.check

table.check attributes
NameRequiredValue
exprtruestring
table.check constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

table.column

table.column attributes
NameRequiredValue
asfalsestring
collatefalsestring
commentfalsestring
defaultfalse

Column default value can be one of:

  1. bool
  2. string
  3. number
  4. Raw expression defined with sql("expr")
nullfalsebool
typetrue

Column type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to type_alias
table.column blocks

table.column.as

table.column.as attributes
NameRequiredValue
exprtruestring
typefalse

enum (PERSISTED)

table.column.generated_always

table.column.generated_always attributes
NameRequiredValue
astrue

enum (ROW_START, ROW_END, TRANSACTION_ID_START, TRANSACTION_ID_END, SEQUENCE_NUMBER_START, SEQUENCE_NUMBER_END)

hiddenfalsebool

table.column.identity

table.column.identity attributes
NameRequiredValue
incrementfalseint
seedfalseint
table.column constraints
ConstraintValue
Requiredfalse
Require Name (e.g., table.column "name" )true
Mutually exclusive sets[as (attribute), as (block)]

table.foreign_key

table.foreign_key attributes
NameRequiredValue
columnstrue

Foreign key columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
on_deletefalse

enum (NO_ACTION, RESTRICT, CASCADE, SET_NULL, SET_DEFAULT)

on_updatefalse

enum (NO_ACTION, RESTRICT, CASCADE, SET_NULL, SET_DEFAULT)

ref_columnstrue

Foreign key reference columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
table.foreign_key constraints
ConstraintValue
Requiredfalse
Require Name (e.g., table.foreign_key "name" )true

table.fulltext

table.fulltext attributes
NameRequiredValue
catalogfalsestring
columnsfalse

List of object reference to column

filegroupfalsestring
primary_keyfalsebool
unique_keyfalse

Object reference to index

table.fulltext blocks

table.fulltext.on

table.fulltext.on attributes
NameRequiredValue
columntrue

Object reference to column

languagefalsestring
semanticfalsebool
typefalse

Object reference to column

table.fulltext.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
table.fulltext constraints
ConstraintValue
Requiredfalse
Require Namefalse
Mutually exclusive sets[primary_key, unique_key], [columns, on]
One of required sets[primary_key, unique_key], [columns, on]

table.index

table.index attributes
NameRequiredValue
columnsfalse

Index columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
fill_factorfalseint
includefalse

Index included columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
nonclusteredfalsebool
typefalse

Index key type can be one of:

  1. string
  2. enum (COLUMNSTORE, HASH, HEAP, SPATIAL, XML)
uniquefalsebool
wherefalsestring
table.index blocks

table.index.on

table.index.on attributes
NameRequiredValue
columnfalse

Index columns can be one of:

  1. Object reference to column
  2. Object reference to table.column
descfalsebool
exprfalsestring
opsfalse

Index operator class can be one of:

  1. string
  2. Raw expression defined with sql("expr")
table.index.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Mutually exclusive sets[column, expr]
table.index constraints
ConstraintValue
Requiredfalse
Require Name (e.g., table.index "name" )true
Mutually exclusive sets[columns, on]
One of required sets[columns, on]

table.period

table.period attributes
NameRequiredValue
endtrue

Object reference to column

starttrue

Object reference to column

typetrue

enum (SYSTEM_TIME)

table.period constraints
ConstraintValue
Requiredfalse
Require Name (e.g., table.period "name" )true

table.primary_key

table.primary_key attributes
NameRequiredValue
columnsfalse

Primary key columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
fill_factorfalseint
includefalse

Primary key included columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
nonclusteredfalsebool
typefalse

Index key type can be one of:

  1. string
  2. enum (HASH)
table.primary_key blocks

table.primary_key.on

table.primary_key.on attributes
NameRequiredValue
columntrue

Primary key columns can be one of:

  1. Object reference to column
  2. Object reference to table.column
descfalsebool
table.primary_key.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
table.primary_key constraints
ConstraintValue
Requiredfalse
Require Namefalse
Mutually exclusive sets[columns, on]
One of required sets[columns, on]

table.system_versioned

table.system_versioned attributes
NameRequiredValue
history_tablefalsestring
retentionfalseint
retention_unitfalse

enum (DAY, WEEK, MONTH, YEAR)

table constraints

ConstraintValue
Requiredfalse
Require Name (e.g., table "name" )true
Allow Qualifier (e.g., table "schema" "name" )true

trigger

The trigger block describes a trigger on a table in a database schema.

trigger "trigger_orders_audit" {
on = table.orders
...
}

trigger attributes

NameRequiredValue
astruestring
execute_asfalse

The execution context of the trigger can be one of:

  1. Raw expression defined with sql("expr")
  2. string
ontrue

Trigger on can be one of:

  1. Object reference to table
  2. Object reference to view
schema_boundfalsebool

trigger blocks

trigger.after

trigger.after attributes
NameRequiredValue
deletefalsebool
insertfalsebool
updatefalsebool
trigger.after constraints
ConstraintValue
Requiredfalse
Require Namefalse
One of required sets[insert, delete, update]

trigger.instead_of

trigger.instead_of attributes
NameRequiredValue
deletefalsebool
insertfalsebool
updatefalsebool
trigger.instead_of constraints
ConstraintValue
Requiredfalse
Require Namefalse
One of required sets[insert, delete, update]

trigger constraints

ConstraintValue
Requiredfalse
Require Name (e.g., trigger "name" )true
Repeatabletrue
Mutually exclusive sets[after, instead_of]
One of required sets[after, instead_of]

type_alias

type_alias attributes

NameRequiredValue
nullfalsebool
schematrue

Object reference to schema

typetrue

Base type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")

type_alias constraints

ConstraintValue
Requiredfalse
Require Name (e.g., type_alias "name" )true
Allow Qualifier (e.g., type_alias "schema" "name" )true

type_table

type_table attributes

NameRequiredValue
schematrue

Object reference to schema

type_table blocks

type_table.check

type_table.check attributes
NameRequiredValue
exprtruestring
type_table.check constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue

type_table.column

type_table.column attributes
NameRequiredValue
asfalsestring
collatefalsestring
commentfalsestring
defaultfalse

Column default value can be one of:

  1. bool
  2. string
  3. number
  4. Raw expression defined with sql("expr")
nullfalsebool
typetrue

Column type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to type_alias
type_table.column blocks

type_table.column.as

type_table.column.as attributes
NameRequiredValue
exprtruestring
typefalse

enum (PERSISTED)

type_table.column.identity

type_table.column.identity attributes
NameRequiredValue
incrementfalseint
seedfalseint
type_table.column constraints
ConstraintValue
Requiredtrue
Require Name (e.g., type_table.column "name" )true
Mutually exclusive sets[as (attribute), as (block)]

type_table.index

type_table.index attributes
NameRequiredValue
columnsfalse

Index columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
includefalse

Index included columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
nonclusteredfalsebool
typefalse

Index key type can be one of:

  1. string
  2. enum (COLUMNSTORE, HASH, HEAP, SPATIAL, XML)
uniquefalsebool
wherefalsestring
type_table.index blocks

type_table.index.on

type_table.index.on attributes
NameRequiredValue
columnfalse

Index columns can be one of:

  1. Object reference to column
  2. Object reference to table.column
descfalsebool
exprfalsestring
opsfalse

Index operator class can be one of:

  1. string
  2. Raw expression defined with sql("expr")
type_table.index.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Mutually exclusive sets[column, expr]
type_table.index constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Mutually exclusive sets[columns, on]
One of required sets[columns, on]

type_table.primary_key

type_table.primary_key attributes
NameRequiredValue
columnsfalse

Primary key columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
fill_factorfalseint
includefalse

Primary key included columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
nonclusteredfalsebool
typefalse

Index key type can be one of:

  1. string
  2. enum (HASH)
type_table.primary_key blocks

type_table.primary_key.on

type_table.primary_key.on attributes
NameRequiredValue
columntrue

Primary key columns can be one of:

  1. Object reference to column
  2. Object reference to table.column
descfalsebool
type_table.primary_key.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
type_table.primary_key constraints
ConstraintValue
Requiredfalse
Require Namefalse
Mutually exclusive sets[columns, on]
One of required sets[columns, on]

type_table constraints

ConstraintValue
Requiredfalse
Require Name (e.g., type_table "name" )true
Allow Qualifier (e.g., type_table "schema" "name" )true

view

The view block describes a view in a database schema.

view "clean_users" {
schema = schema.public
column "id" {
type = int
}
...
}

view attributes

NameRequiredValue
astruestring
check_optionfalse

enum (LOCAL, LOCAL, CASCADED)

commentfalsestring
depends_onfalse

List of object references

schematrue

Object reference to schema

schema_boundfalsebool

view blocks

view.column

view.column attributes
NameRequiredValue
nullfalsebool
typetrue

Column type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to type_alias
view.column constraints
ConstraintValue
Requiredfalse
Require Name (e.g., view.column "name" )true

view.fulltext

view.fulltext attributes
NameRequiredValue
catalogfalsestring
columnsfalse

List of object reference to column

filegroupfalsestring
primary_keyfalsebool
unique_keyfalse

Object reference to index

view.fulltext blocks

view.fulltext.on

view.fulltext.on attributes
NameRequiredValue
columntrue

Object reference to column

languagefalsestring
semanticfalsebool
typefalse

Object reference to column

view.fulltext.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
view.fulltext constraints
ConstraintValue
Requiredfalse
Require Namefalse
Mutually exclusive sets[primary_key, unique_key], [columns, on]
One of required sets[primary_key, unique_key], [columns, on]

view.index

view.index attributes
NameRequiredValue
columnsfalse

Index columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
includefalse

Index included columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
nonclusteredfalsebool
typefalse

Index key type can be one of:

  1. string
  2. enum (COLUMNSTORE, HASH, HEAP, SPATIAL, XML)
uniquefalsebool
wherefalsestring
view.index blocks

view.index.on

view.index.on attributes
NameRequiredValue
columnfalse

Index columns can be one of:

  1. Object reference to column
  2. Object reference to table.column
descfalsebool
exprfalsestring
opsfalse

Index operator class can be one of:

  1. string
  2. Raw expression defined with sql("expr")
view.index.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Mutually exclusive sets[column, expr]
view.index constraints
ConstraintValue
Requiredfalse
Require Name (e.g., view.index "name" )true
Mutually exclusive sets[columns, on]
One of required sets[columns, on]

view constraints

ConstraintValue
Requiredfalse
Require Name (e.g., view "name" )true
Allow Qualifier (e.g., view "schema" "name" )true