how to create user defined Type in Sql

前端 未结 2 1136
我在风中等你
我在风中等你 2021-01-07 03:01

i don\'t know how to create a domain with optional constrains? i tried

CREATE DOMAIN idx INT CHECK (VALUE > 100 AND VALUE < 999);

bu

2条回答
  •  有刺的猬
    2021-01-07 03:34

    CREATE TYPE myType AS TABLE
    (
       idx INT,
       CHECK (idx > 100 AND idx < 999)
    )
    

    Or you can also create rules and bind them to your type.

    CREATE TYPE [dbo].[myType] 
    FROM [INT] NOT NULL
    GO
    
    CREATE RULE multiplyByTen
    AS @myType % 10 = 0
    AND @myType > 100
    AND @myType < 999
    

    Then Bind Rule

    EXEC sp_bindrule 'multiplyByTen', 'myType'
    

提交回复
热议问题