Entering Metadata Statements
In this exercise, you use the CREATE DOMAIN statement to create domains that you will use later to specify column datatypes.
Create Some Domains
In the following exercise you will define four domains. The first three specify only a datatype. The fourth one is more complex. In each case, the domain will be useful for several different columns, not just the column for which it is named.
- Note: You should be connected to the
TUTORIALdatabase when you begin this exercise.
- Click on the SQL icon (
) and type the following code in the SQL Statement Area to define a domain called FIRSTNAME that has a datatype of VARCHAR(15).
CREATE DOMAIN FIRSTNAME AS VARCHAR(15)
- Execute the statement: click
, press F5, or choose Query > Execute.
- Now create two more domains, LASTNAME and EMPNO. Execute each statement separately before entering the next one.
CREATE DOMAIN LASTNAME AS VARCHAR(20)CREATE DOMAIN EMPNO AS SMALLINT
- Now create two more domains, LASTNAME and EMPNO. Execute each statement separately before entering the next one.
- Next, enter and execute the following code to define a domain for department numbers. The domain is defined as a three-character string. In addition to the datatype, it includes check constraints to ensure that the department number is either “000”, alphabetically between “0” and “999”, or NULL. Pay attention to parentheses and quotes as you enter this:
CREATE DOMAIN DEPTNO AS CHAR(3)CHECK (VALUE = '000'- OR (VALUE > '0' AND VALUE <= '999')
OR VALUE IS NULL)