dcsimg
Results 1 to 2 of 2

Thread: Can i create Custom check constraint in SQL Server?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2019
    Location
    Ahmedabad
    Posts
    18

    Can i create Custom check constraint in SQL Server?

    I have a table 'City' having columns as 'ID' , 'Name' and 'Number'.
    If Name is 'AA' then Number column shouldn't accept null values. If name is other than 'AA' Number column can be null

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    1,999

    Re: Can i create Custom check constraint in SQL Server?

    ?
    Aircode. No real experience in MSSQL. No idea where the "NOT" goes

    CHECK (Name='AA' AND Number NOT IS NULL)


    https://docs.microsoft.com/en-us/sql...l-server-ver15
    One System to rule them all, One IDE to find them,
    One Code to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    For health reasons i try to avoid reading unformatted Code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width