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

How to create a custom CHECK in Oracle

I have to create a database for my project and im currently struggling with creating custom checks. I want to create custom check on student personal identity number (pesel),I want it to be 11 characters long and to have only numbers from 0-9,also i…
Sassanek
  • 3
  • 1
-1
votes
1 answer

Create a table for following condition

condition for the problem to be solved: The code i tried to do is create table article ( ArCode CHAR(5), ArName VARCHAR(30) NOT NULL , Rate Number(8,2) , Quantity NUMBER(4) CHECK (Quantity>0) DEFAULT 0 , Class CHAR(1) ); I…
-1
votes
4 answers

Check constraint to prevent 2 or more rows from having numeric value of 1

I have a SQL table with a column called [applied], only one row from all rows can be applied ( have the value of 1) all other rows should have the value 0 Is there a check constraint that i can write to force such a case?
Maayan Hope
  • 1,482
  • 17
  • 32
-1
votes
2 answers

How to replace a constraint in sql?

i have a Question, "why have i create first a new constraint and then delete the old constraint? Why in this order?" i want underline that my Question is for the sequence, why this sequence? select * from user_constraints; alter table unipc add…
-1
votes
1 answer

Alter table clg ADD CONSTRAINT UC_Person NOT NULL(AGE); why do I get an error?

This throws an error: ALTER TABLE TABLE_NAME ADD CONSTRAINT UC_Person NOT NULL(AGE); This works fine: ALTER TABLE TABLE_NAME MODIFY Column_name data_type not null; Question is that 1st one why getting the error and for unique will not…
Naveen kumar
  • 1
  • 1
  • 1
-1
votes
1 answer

Check Constraint/Triggers

I am trying to put a constraint on a column when creating a table, namely I want 'numberOfNights' to be restricted to >=1 and <=3. I cannot get it to work; I think I may need a trigger but I am unsure. Part of the reason I am confused is because I…
-1
votes
1 answer

Constraint on a column based on another column

I have a table "Table" that contains an ID, Col1 and Col2, Col3. Col2 can either be 0 or 1. I want Col2 in rows where Col1 has the same value to be the same. Ex I want something like this +----+-------+------+-----------+ | ID | Col1 | Col2 | …
Elmehdi93
  • 70
  • 1
  • 9
-1
votes
1 answer

Constrain a numeric array to be sorted and unique

I have a numeric[] column in a Postgres database that should represent an array of times (like {0.5 seconds, 2 seconds, 3.25 seconds, ...}). As such I would like to constrain the values in the array to be unique and sorted. Is there any way to do…
user1475412
  • 1,659
  • 2
  • 22
  • 30
-1
votes
2 answers

Adding constraint in the column oracle

I am facing issue adding constraint to the column of table in oracle- The column is defined with the datatype char(500 char). I need to put the constraint which allows only the digits and N/A value to be inserted in the column.
smrita
  • 7
  • 2
-1
votes
1 answer

SQL CHECK CONSTRAINT .. iS NOT WORKING WITH ME

MY QUESTION IS THE FOLLOWING : Create a new table named frequent travelers (FreqTrav). It will only store passengers who have taken more than 2 trips with the company. It will record the passenger name, passenger number, address, phone number, total…
HODA
  • 1
  • 3
-1
votes
1 answer

TransactionScope fails check constraint

I am having a issue using TransactionScope and a check constraint in SQL Server. I want to insert into the table as such: Col A | Col B ------------ Dave | 0 Fred | 1 The table has a check constraint that there must always be an entry in Col B…
DasDave
  • 801
  • 1
  • 9
  • 28
-1
votes
1 answer

Check Constraint for Money

I have a need for a Check Constraint on a single column that is used to express dollars paid for a service/product. I want this check constraint to check to make sure there are no leading spaces (e.g. LEFT(1)<>''), no tailing spaces (e.g.…
Hukd
  • 35
  • 7
-1
votes
1 answer

Microsoft SQL Constraint - limit driver from forbidden site

I'm using Microsoft SQL server 2008 and I need to create a constraint that will prevent a [Tx] from being created/updated if the [Driver] is not allowed to either the source [Shipper] or destination [Consignee] site. Tables: Drivers (holds…
Alan B. Dee
  • 5,490
  • 4
  • 34
  • 29
-1
votes
2 answers

Using a check constraint to ensure that a varchar includes letters and numbers

I am trying to create a check constraint to ensure that a stored varchar has atleast 1 letter and 1 number and am not sure exactly how to do this. Any help would be appreciated. This is what I have so far: CHECK (VALUE LIKE [a-z] AND LIKE…
-1
votes
2 answers

Is it possible to have an equality constraint in SQL?

I have the following: create table dbo.Users ( Id int identity not null constraint PK_Users_Id primary key clustered (Id), Email nvarchar (120) not null constraint UQ_Users_Email unique (Email), Username nvarchar (120) not null …
Miguel Moura
  • 36,732
  • 85
  • 259
  • 481
1 2 3
41
42