Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.1 » SQL Anywhere Server - SQL Usage » Data integrity » Domains


Creating domains

Administrators can create domains and assign them to columns in Sybase Central.


DBA authority.

Context and remarks

Some predefined domains are included with SQL Anywhere. For example, the monetary domain MONEY.

 Create a new domain (Sybase Central)
  1. Use the SQL Anywhere 12 plug-in to connect to the database.

  2. In the left pane, right-click Domains and click New » Domain.

  3. Follow the instructions in the Create Domain Wizard.

 Assign a domain to a column (Sybase Central)
  1. Use the SQL Anywhere 12 plug-in to connect to the database.

  2. In the left pane, double-click Tables.

  3. Click the table.

  4. In the right pane, click the Columns tab.

  5. Select a column and in the Data Type field click the ellipsis (three dots) button.

  6. Click the Data Type tab and click Domain.

  7. In the Domain list, select a domain.

  8. Click OK.


The domain is created and assigned to the specified column.




Some columns in the database are used for employee names and others to store addresses. You might then define the following domains.

CREATE DOMAIN persons_name CHAR(30)
CREATE DOMAIN street_address CHAR(35);


Having defined these domains, you can use them much as you would the built-in data types. For example, you can use these definitions to define a table, as follows.

CREATE TABLE Customers (
   Name persons_name,
   Street street_address);


In the above example, the table's primary key is specified to be of type integer. Indeed, many of your tables may require similar identifiers. Instead of specifying that these are integers, it is much more convenient to create an identifier domain for use in these applications.

When you create a domain, you can specify a default value and provide check constraint to ensure that no inappropriate values are typed into any column of this type.

Integer values are commonly used as table identifiers. A good choice for unique identifiers is to use positive integers. Since such identifiers are likely to be used in many tables, you could define the following domain.


Using this definition, you can rewrite the definition of the Customers table, shown above.

CREATE TABLE Customers2 (
   ID identifier PRIMARY KEY,
   Name persons_name,
   Street street_address

 See also