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
0
votes
1 answer

Enforce multi-table database logic in PostgreSQL

Is there a way to enforce database logic that spans tables? As a very VERY simple super-cut-down example, imagine a two-table invoice system: create table accounts (id serial primary key, balance integer not null default 0); create table invoices…
rosuav
  • 466
  • 4
  • 12
0
votes
1 answer

SQL Constraint on column value depending on value of other column

First, I have simple [SomeType] table, with columns [ID] and [Name]. Also I have [SomeTable] table, with fields like: [ID], [SomeTypeID] (FK), [UserID] (FK), [IsExpression] Finally, I have to made on database layer a constraint that: for…
prvit
  • 956
  • 3
  • 9
  • 22
0
votes
1 answer

Check constraint on multiple columns for BETWEEN

CREATE TABLE item( id int, number1 float, number2 float, number3 float, number 4 float, PRIMARY KEY(id), CONSTRAINT valid_numbers CHECK( (number1 BETWEEN -1 and 1) AND (number2 BETWEEN -1 and 1) AND (number3 BETWEEN -1 and 1) AND (number4 BETWEEN…
huynhing
  • 1
  • 1
0
votes
2 answers

mysql and trigger usage question

I have a situation in which I don't want inserts to take place (the transaction should rollback) if a certain condition is met. I could write this logic in the application code, but say for some reason, it has to be written in MySQL itself (say…
dhruvbird
  • 6,061
  • 6
  • 34
  • 39
0
votes
1 answer

check constraint for day and month only in Oracle SQL

So I need a constraint that will prevent a user from entering a day/month other than the first day of the quarter and last day of the quarter, as well as a date that the table will be 'locked' for editing. I did some searching online, and thought I…
patkipper
  • 1
  • 1
0
votes
1 answer

Oracle: constraint check number range collision

is there any way to check empty intersection of number range by constraint? Example: CREATE TABLE "AGE_CATEGORIES" ( "AGE_CATEGORY_ID" CHAR(2 BYTE) NOT NULL PRIMARY KEY, "NAME" NVARCHAR2(32) NOT NULL, "RANGE_FROM" NUMBER(*,0) NOT NULL, …
Honza
  • 939
  • 2
  • 11
  • 28
0
votes
1 answer

Jpa OneToMany Relation not woriking

I have an issue trying to persist an Entity with a @OneToMany Relatioship and I don't get it solved. (Sorry, I'm not an english native speaker). These are the Entities: @Entity @Table(name =…
Rubén
  • 427
  • 1
  • 9
  • 23
0
votes
4 answers

Ensure Oracle row represents a unique timespan

I have to make a process in Oracle/PLSQL. I have to verify that the interval of time between start_date and end_date from a new row that I create must not intersect other start_dates and end_dates from other rows. Now I need to check each row for…
Dan F.
  • 345
  • 1
  • 3
  • 12
0
votes
0 answers

Minizinc soft constraint issue

i'm facing an issue with a Minizinc code that have to schedule some exams in available rooms and periods. I skip the entire problem and code, because i've just a problem in the definition of this soft constraint: some exams are targeted as…
0
votes
1 answer

EF6 - Entity with navigation property but without FK

How can I create an entity, with a navigation property to another entity, but without creating the Foreign Key. Ex: class EntityType { Id, Code, Description } class Entity { Id, Name, Age, EntityType, EntityTypeId} class EntityHistory { Id,…
0
votes
0 answers

MySQL 5.6 Check Constraint Implementation

I was trying to add a check constraint to my create table DDL in the following manner: CREATE TABLE TYPE_SCENE ( ID_TYPE_SCENE INTEGER(10) PRIMARY KEY AUTO_INCREMENT, ID_TYPE INTEGER(10) NOT NULL, CREATED_BY VARCHAR(20) NOT NULL, …
Aman Mohammed
  • 2,878
  • 5
  • 25
  • 39
0
votes
2 answers

Using sql function on CHECK constraint for newly inserted row

First of all i need help with this for my bachelor thesis. I'm doing the whole database on sql server 2008 Release 2. The problem is with check constraint that is using a function that is working on her own but not with the use in the constraint.…
0
votes
1 answer

Modify value in check constraint

Is it possible to change the value of a column in a check constraint in sql-server? For example I want to be able to test for not NULL like so: CHECK (column IS NULL) But change the column to an empty string if this evaluates to true. I'm not an…
Tom
  • 3,006
  • 6
  • 33
  • 54
0
votes
0 answers

SQL Server, FK: Check in the (1) side NoCheck in the (Many) side

Suppose I have an ActiveCustomers table with some FKs (eg CountryID), and I also have a NonActiveCustomers with the same FKs. When I insert a new line to ActiveCustomers - the system must check the "1" side (from 1:N) to verify the CountryID (or…
Geri Reshef
  • 397
  • 1
  • 6
  • 17
0
votes
2 answers

Constraint with Query

There are two tables City (Name, Country_code, Population) Country (Name, Code, Population) The task is: The sum of population of all cities in a country, should be less or equal to population of a country. - Create a constraint and an…
nlimits
  • 103
  • 1
  • 12