请问怎么在sql添加约束为订金,租金,广告费,库房租金,施压抵金???????

解决方案 »

  1.   


    Alter Table [Tablename] Add Constraint [ChekcName] Check ([ColName]='定金' Or [ColName]='租金' Or....)
      

  2.   


    create table #t(col varchar(300),
    CONSTRAINT chk_col CHECK (col='订金' or col='租金'
    or col='广告费' or col='库房租金' or col='施压抵金')
    )
    insert into #t(col)
    select '广告费'select * from #t
    drop table #t
      

  3.   

    --#1.
    CREATE TABLE #temp
    (
    Id int NOT NULL,
    [name] NVARCHAR(10),
    CHECK (CHARINDEX([name]+N',', N'订金,租金,广告费,库房租金,施压抵金') > 0)
    )
    --#2.
    CREATE TABLE #temp1
    (
    Id int NOT NULL,
    [name] NVARCHAR(10),
    CHECK ([name] IN (N'订金', N'租金', N'广告费', N'库房租金', N'施压抵金'))
    )
    --TEST:
    INSERT #temp
    SELECT 1, N'test' --失败INSERT #temp
    SELECT 1, N'订金' --成功
      

  4.   

    Alter Table [Tablename] Add Constraint [ChekcName] Check ([ColName]='定金' Or [ColName]='租金')
      

  5.   

    Alter Table [chargenotice] Add Constraint [beepstype] Check ([beepstype]='定金' Or [beepstype]='租金'or[beepstype]='广告费'or[beepstype]='库房定金'or[beepstype]='施抵押金') 
    这样对么?