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 Business Rules during SQL Server Insert (Check Constraint?)

We have some business rules that enforce things such as Employee's can only have one current activity (Todo, In-Progress), and all others must be a different State (Completed, Removed) We've noticed that sometimes we get duplicate activities entered…
John
  • 6,503
  • 3
  • 37
  • 58
0
votes
1 answer

How to add MSSQL constraint to limit the number of related tables

I have a parent table with a relationship to each of four child tables. The primary key of the parent table forms both the primary and foreign key for the child tables. For any given row in the parent table, there can only be two child tables…
0
votes
1 answer

Minizinc: is this constraint possible?

I'd like to figure out how to write this constraint: I have a list of exams,every exam has a duration; the final output is the display of a real timetable, in the columns there are the available hours, four in the morning and four in the afternoon,…
0
votes
0 answers

Using check constraint for event capacity

I am designing a database for a tour event. I need to write a check constraint that monitors the tour ticket sales (TicketID) and tourcapacity. it stops sell of tickets when the maximum tourcapacity is reached. how do i write the code for a…
Joseph
  • 313
  • 1
  • 4
  • 16
0
votes
1 answer

How can I disable constraint at table creation time : SQL Server 2008

I want to create an additional table in my database : CREATE TABLE "DEM_TRACE" ( "Id" NUMERIC(6), "Indice" VARCHAR(3), "Sec_Id" NUMERIC(10), "QUOTE_PART_NUM" NUMERIC(38) DEFAULT 0, "QUOTE_PART_DEN"…
mounaim
  • 1,132
  • 7
  • 29
  • 56
0
votes
3 answers

How to use oracle check constraints to limit number of registration?

I've a user table with unique user_id. User can register using there id. Now I want to limit the max. registration per user using CHECK constraints. so I use this: .... CHECK(select count(user_id) from user where ... ...) But it's show subquery…
Sondhi
  • 51
  • 1
  • 4
  • 9
0
votes
3 answers

Will AutoIncrement work with Check constraints?

The question is simple: In SQLite, if I choose to AutoIncrement a primary key of type NUMERIC which has a check constraint like CHECK(LENGTH(ID) == 10), will it work correctly inserting the first value as 0000000001 and so on?
0
votes
2 answers

How do I create a check to make sure a value exists in another table?

Right now I have two tables, one that contains a compound primary key and another that that references one of the values of the primary key but is a one-to-many relationship between Product and Mapping. The following is an idea of the setup: CREATE…
rjzii
  • 14,236
  • 12
  • 79
  • 119
0
votes
1 answer

Is there an alternative to performing a check constraint with subqueries?

I have two tables Table Room( capacity INTEGER, roomID varchar(5) ) and Event( attendance INTEGER, room varchar(5), CHECK(attendance <= (SELECT R.capacity FROM Room R, WHERE R.roomID = room)) ) But I guess MySQL doesn't allow for…
geoxile
  • 348
  • 1
  • 6
  • 16
0
votes
1 answer

SQL Table Variables - adding constraint that checks for existence of matching row set

Updating with pmbAustin's suggestion pmbAustin, thanks. I think that will work. I've created a function "dbo.CK_WinteamSportExists" that returns a 0 or 1. However I'm now getting a baffling error message. When I tested my solution I get the…
0
votes
1 answer

How to I get a multiple column constraint to work in SQL server

I have a case where if the Id field is a specific value, I don't want to allow null in another field, but if the Id value <> a specific value, null is ok. In the example below, inserting the first record should succeed, the second should succeed,…
sqlpadawan
  • 305
  • 1
  • 5
  • 15
0
votes
1 answer

How do I put a check constraint on the first letter of names in Oracle

I am new at SQLPlus and I want to enforce a CHECK CONSTRAINT on a column that stores names. I want the constraint to not allow for names to be entered that starts with a Q. this is what I have: ALTER TABLE table1 ADD CONSTRAINT table1_name_ck CHECK(…
truffle
  • 455
  • 1
  • 9
  • 17
0
votes
3 answers

Check constraint on date

I am creating a table with date column. I would like to add a check constraint to validate if the date is in future. create table test_table ( schedule_date date not null, check (schedule_date >= TODAY) ); Above sql gives me a syntax error.…
usha
  • 28,973
  • 5
  • 72
  • 93
0
votes
2 answers

Specify a field with at most two values equal on mysql

How can I specify on mysql that I want a field which can take at most two values ​​equal? Is it possible with the check instruction?
Seba92
  • 446
  • 1
  • 4
  • 17
0
votes
1 answer

alter table to add contraint using a case statement?

I'm working in APEX making a form for users to reserve a building. I'm trying to add ckecks to the number_guests column so that, based on the date and building number, users can only enter a certain amount of guests (10 between Memorial Day and…