Questions tagged [check-constraint]

Check constraints in a relational database ensure that only certain values can be stored in one (or more columns). Check constraints can only validate columns of a single row.

Check constraints validate the value of one or more columns in a single row of a relational table. Typical check constraints are salary > 0 (validating a single column) or hire_date < fire_date (validating the dependency between two columns).

Check constraints can not be used to validate columns between different rows.

All relational DBMS except MySQL support check constraints.

77 questions
0
votes
0 answers

MSSQL create table CHECK for sub-query

I guess no sub-queries are allowed in "CREATE TABLE CHECK" (only current values allowed). But I would like to check the table for condition outer the current row like below: Pseudocode: CREATE TABLE Persons ( LoginName varchar(128) NOT NULL CHECK…
procma
  • 1,174
  • 3
  • 14
  • 24
0
votes
1 answer

What logic error do I have in this SQL check constraint?

I spent hours last night trying to figure out what's wrong with the check constraint below. I want to enforce the following rule: Either all rows are null Or Col1 is not null and only one of the other columns is not null (if col4 is set, it should…
Mark13426
  • 2,569
  • 6
  • 41
  • 75
0
votes
1 answer

Microsoft SQL Server - check constraint error when using stored procedure (msg 547)

I keep getting the following error: Msg 547, Level 16, State 0, Procedure add_new_customer, Line 6 The INSERT statement conflicted with the CHECK constraint "CK__customer__addres__09A971A2". The conflict occurred in database "AIT 732 - Bank",…
Just_Some_Guy
  • 330
  • 5
  • 24
0
votes
3 answers

Check Constraint- Check password contains atleast one number/special Character/uppercase

I'm looking to create three separate check constraints for my SQL Server database to ensure that a password field constrains a minimum of one number, one uppercase character and one special character. I consider the best way to approach is by…
Matt_Johndon
  • 204
  • 1
  • 6
  • 15
0
votes
0 answers

Check constraint for distribution of probability in DB2

I have in DB2 a table with a VARCHAR column containing a probability distribution, such as "0.3, 0.1, 0.3, 0.2, 0.1". I'm wondering if I could create a check constraint for this column in order to check that the sum of the probabilities is indeed 1.…
user998692
  • 5,172
  • 7
  • 40
  • 63
0
votes
2 answers

Sql Check constraint?

I am working on C# app using SQL Server as database here is a very simple problem which I could not find out till now. I created a check constraint on my QUANTITY column like this: QUANTITY >= 0 The quantity is updating from C# and I don't want the…
Kretos
  • 91
  • 1
  • 3
  • 10
0
votes
1 answer

SQL Extended Check Constraint

Is it possible to have a complex Check Constraint? for example I have a customers table each record of which is assigned a customer type. therefore I could have several customers with the same type. I want to set one customer for each type to be the…
Steven Wood
  • 2,675
  • 3
  • 26
  • 51
0
votes
3 answers

How to delete a mysql-enum-like column in sql server?

in orther to get a column similar to the mysql ENUM type, I wrote a sql query as follows ALTER TABLE [DbName].[dbo].[MediaContent] ADD MediaType nvarchar(50) check(MediaType in ('audio','video','song','other')) this worked as wished(for test):…
Bellash
  • 7,560
  • 6
  • 53
  • 86
0
votes
2 answers

Why doesn't this Check constraint work?

I have created a check constraint in SQL Server 2005, but this check constraint doesn't work. The SQL Server Management Studio tells me by an insert statement the following message: Msg 547, Level 16, State 0, Line 1 The INSERT statement…
0
votes
1 answer

Check if a certain column contains a certain value when updating another column

I'm having some trouble to find an easy way to check if a column contains a certain value before updating the value in another column in a table row. For example, if I have the table StudentsParticipationInClass like below | ID | Grade | …
ccb3
  • 39
  • 6
0
votes
1 answer

Checking the length of a string provided

I'm trying to define a domain which will allow to pass only 6 chars strings. I'm declaring it in a following way: create domain aircrafts_reg_nos as char(6) check(length(@value) = 6) But this doesn't seem to catch strings which are longer than 6…
smallB
  • 16,662
  • 33
  • 107
  • 151
-1
votes
1 answer

Avoiding duplicate rows being inserted in where unizue rows are obtained from two tables

I have a two tables such as customer_name and customer_phone, but the unique customer is identified from the combination of all the four columns from two of the tables. Since we have multiple souce systems inserting into the below tables at the…
-2
votes
2 answers

how to add check constraint in oracle

I have a table, create table a( id_a number(5) not null, name varchar2(15) not null, address varchar2(30), phone varchar2(15), constraint pk_a primary key (id_a) ); I want add constraint check at phone. example. phone is 08175210868 I want to…
newbie
  • 41
  • 1
  • 1
  • 6
-3
votes
2 answers

Unsure how to phrase plsql exception

I want to write an exception for the Check column. If 'Ok' or 'Not Ok' have not been entered i want to raise an application error. How would i go about writing this?
Mike Dark
  • 1
  • 4
-3
votes
1 answer

Querying Microsoft SQL Server 2012 70-461 book

One of the questions in the book ask the following: Test the check constraint CHK_Products_unitprice in the Production.Products table by using the same kind of logic you used in the Lesson 2 exercise. Try to insert a new row with all valid …
TheWommies
  • 4,922
  • 11
  • 61
  • 79