locked
SQL server equivalent for 'CREATE DOMAIN' with 'CHECK' RRS feed

  • Question

  • What is the equivalent for domain creation in ms sql server?

    The code below is only an example, i have to use CREATE TYPE and CHECK(or any equivalent).

    CREATE TYPE ROOM_TYPE FROM CHAR(6) NOT NULL CHECK(VALUE IN 'SINGLE','COUPLE');

    Sunday, August 21, 2016 6:25 PM

Answers

  • Hi,

    I believe you're looking for:

    Constrain one specific column

    ALTER TABLE <table>
    ADD CONSTRAINT chk_val CHECK (col in ('SINGLE','COUPLE'))

    Create Specialized Type:
    https://msdn.microsoft.com/nl-nl/library/ms175007.aspx

    but this will allow you to create a special data-type that always has the constrain :).
    Though it is not recognized outside your database I am to novice in this area to say if it really gives huge amounts of trouble.
    All I know is that getting data out of them with SSIS or T-SQL to import in different database is always a hassle.

    Sebastian


    Sunday, August 21, 2016 6:45 PM