Questions tagged [check-constraints]

CHECK constraints enforce domain integrity by limiting the values that are accepted by one or more columns.

SQL CHECK constraints enforce domain integrity by limiting the values that are accepted by one or more columns.

You can create a CHECK constraint with any logical (Boolean) expression that returns TRUE or FALSE based on the logical operators. For example, the range of values for a salary column can be limited by creating a CHECK constraint that allows for only data that ranges from $15,000 through $100,000. This prevents salaries from being entered beyond the regular salary range. The logical expression would be the following: salary >= 15000 AND salary <= 100000.

624 questions
-2
votes
1 answer

PostgreSQL check if column A is null then B must be null

I am new to PostgreSQL checks. I need to add a check constraint that specifies if column A is null, then B must be null But both can be NOT NULL In probably more understandable words, if a row is inserted, both A and B columns has to be populated,…
SeekanDestroy
  • 511
  • 1
  • 5
  • 12
-2
votes
1 answer

PostgreSQL custom CHECK on column

I have the following table: DROP TABLE IF EXISTS employees; CREATE TABLE cars ( model VARCHAR (50), brand VARCHAR (50), price INTEGER ); Which looks like the following: model brand price Clio Renault 3000 Clio …
-2
votes
1 answer

DDL: SQL Question Check Constraint on multiple columns

create table Game( isOn boolean, playHour int, isOff boolean, constraint ck_isOn_hour check ( ? ) ); Constraint : playHour is NULL when isOn = FALSE Replace the '?' symbol with a valid check for the given constraint. Any help is much…
kris
  • 1
  • 1
-2
votes
1 answer

nvarchar needs to contain only english or georgian letters

My constraint: (datalength([Firstname])>=(2) AND datalength([Firstname])<=(50) AND (NOT [Firstname] like '%[^a-zA-Z]%' AND NOT [Firstname] like N'%[^ა-ზ]%')) Adding first name with Georgian letters causes error: What's wrong?
-2
votes
2 answers

check constraint to check inserted date

I want to check the user's birthday should be greater than 18 years. I have used below mentioned check constraint. (FLOOR((MONTHS_BETWEEN(DOB,SYSDATE))/12))>=18 DOB: field in table for birthdate. but following error has occurred: DOB is invalid…
-3
votes
1 answer

Table Reviews for other 3 Different Tables

I have 3 tables: Books (BookId PK, ...) Posts (PostId PK, ...) Users (UserId PK, ...) And I need to create Reviews for all of them. Should I use a table Reviews: Reviews (ReviewId PK, BookId FK, PostId FK, UserId FK) And than with a Check…
Miguel Moura
  • 36,732
  • 85
  • 259
  • 481
-3
votes
2 answers

Adding a Check Constraint in SQL

For below table, How to add a Constraint in SQL to enforce a maximum of one AddressID has Primary = TRUE where EndDate = 12/31/9999 ?
user3749816
  • 77
  • 1
  • 1
  • 7
-4
votes
2 answers

SQL: Is it possible to block a table insert just prior to the completion of a transaction?

TL;DR: My real question is in the title, is it possible to block a table insert just prior to the completion of a transaction, that is, only concerning the data as it would be right before the transaction would be committed? UPDATE: What procedes is…
-4
votes
1 answer

SQL : Column check constraint cannot reference other columns. (for different tables)

I have two tables: T1(A,B) where create table T1( A char(2) NOT NULL primary key check(T1.A not in T2.B), B char(2) unique ); T2(C,B) where create table T2( C number(2) primary key, B char(2) unique references T1 check(T1.B not in T1.A) ); Here,…
denizen
  • 458
  • 1
  • 5
  • 15
1 2 3
41
42