Questions tagged [constraints]

A constraint is a condition that has to be fulfilled in a given context. Constraints are typically used in databases and programming languages to detect errors, ensure data consistency, accuracy, and to enforce business requirements.

A constraint is a condition that has to be fulfilled in a given context. Constraints are typically used in databases and programming languages to detect errors, ensure data consistency, accuracy, and to enforce business requirements. Constraints are also important in optimization problems. Constraints can be either hard constraints which set conditions for the variables that are required to be satisfied, or soft constraints which have some variable values that are penalized in the objective function if, and based on the extent that, the conditions on the variables are not satisfied.

For example, database constraints can be:

  • NOT NULL Constraint - a column cannot have NULL value.

  • DEFAULT Constraint - a default value for a column when none is specified.

  • UNIQUE Constraint - all values in a column are different.

  • CHECK Constraint - all values in a column satisfy certain criteria.

Further reading

What are database constraints?

8809 questions
3
votes
3 answers

Delete or change the primary key constraint to UNIQUE constraint using SQL Server 2008

I really need to know if there is any way I can change or delete the primary key constraint of a table to UNIQUE constraint When I try to drop the primary constraint from the Entreprise table: ALTER TABLE Entreprise DROP CONSTRAINT …
Yassine edouiri
  • 281
  • 3
  • 14
  • 30
3
votes
4 answers

Cannot implement a multiple generic parameter based method with constraints?

I have the following Interface Declaration: public interface IBasePresenter { void Run(); void ShowDialog(T t, M m ) where T : UserControl where M : Form, ISomeInterface; } The ShowDialog() is basically a method that…
IbrarMumtaz
  • 4,235
  • 7
  • 44
  • 63
3
votes
3 answers

Foreign key for Father to be male, Mother to be female and you can't be your own mother/father

I have 3 tables: CREATE TABLE "Names" ( "Name" TEXT(20) NOT NULL, "Gender" TEXT(20) NOT NULL, PRIMARY KEY ("Name", "Gender") ); CREATE TABLE "Snames" ( "Sname" TEXT(20) NOT NULL, PRIMARY KEY ("Sname") ); CREATE TABLE "People" ( "ID" INTEGER NOT…
Ashley
  • 487
  • 7
  • 19
3
votes
4 answers

Oracle SQL Constraint where clause

I have the table Tester on oracle with the following columns: TesterID TesterName IsDefault Application_ID TesterID is the primary key. Now I want that there can only be one Default Tester, which means only one Tester can have the calues…
John Smithv1
  • 673
  • 5
  • 14
  • 33
3
votes
2 answers

python-constraint Allequal

This question is about the python package constraint (see http://labix.org/python-constraint), in particular the built-in "AllEqualConstraint". In a problem involving 4 variables, I would like to enforce the first two and the second two to be equal,…
Leevi L
  • 1,538
  • 2
  • 13
  • 28
3
votes
1 answer

How to find all references of a particular primary key in a sqlite table?

I have set PRAGMA foreign_keys=ON; I'm trying to delete some records in a sqlite3 table and it displays Error: constraint failed sqlite> delete from auth_user where id = 110; Error: constraint failed It works if the PRAGMA foreign_keys was OFF. The…
Vigneshwaran
  • 3,265
  • 6
  • 23
  • 36
3
votes
3 answers

C# Type Conversion Error Despite Generic Constraint

Why, with a generic constraint on type parameter T of class P of "must inherit from A", does the first call succeed but the second call fail with the type conversion error detailed in the comment: abstract class A { } static class S { public…
acdx
  • 782
  • 1
  • 6
  • 13
3
votes
2 answers

Xcode 4.4 constraint errors

I am using Xcode 4.4 and creating my views in interface builder. When I run my app, I consistently get the following constraint errors. Unable to simultaneously satisfy constraints: ( "
David
  • 14,205
  • 20
  • 97
  • 144
3
votes
3 answers

How to create a unique index with conditional and subquery in PostgreSQL?

I use PGSQL and try add the index below. CREATE UNIQUE INDEX fk_client ON user_client (fk_client) WHERE fk_client NOT IN(SELECT fk_client FROM legal_entity); But ... It is not possible, because there is allowed run a sub query in the creation of an…
FabianoLothor
  • 2,752
  • 4
  • 25
  • 39
3
votes
2 answers

Hibernate many to many association delete error

I have two classes: Employee and Award, with a many-to-many relationship. When trying to delete I get a constraint violation error. I went through all the posts but none were helpful. This is the code: @Entity @Table(name="TB_AWARD") public class…
Chetan Pulate
  • 503
  • 1
  • 7
  • 21
3
votes
2 answers

SQLAlchemy does not create Foreign keys on MySQL [Debian Linux]

For same code snippet, SQLAlchemy creates Foreign Key constraint on Mac OX, however, it fails to create foreign key constraint on Debian Linux. Environment & Libraries: Python 2.7 SQLAlchemy 0.7.8 MySQL-python-1.2.3 [This is the connector, and I am…
Aijazs
  • 426
  • 4
  • 8
3
votes
1 answer

How do you provide security authentication for a ResourceHandler in Jetty without XML?

I'm trying to provide authentication of one of my pages on my Jetty server. I'm doing it all programatically, so there's no xml involved. I've found I can protect particular contexts by using the ConstraintSecurityHandler. While this works fine for…
user1455951
  • 41
  • 1
  • 3
3
votes
1 answer

SQL Server Check Constraint Inquiry

I have a table which stores payments and want to ensure if the payment method is a credit card then the card type field should be IN ('Visa', 'MasterCard', 'Discover', 'American Express'), however if the payment method is not a credit card then the…
Chris Klepeis
  • 9,783
  • 16
  • 83
  • 149
3
votes
2 answers

I'm trying to search a long column with like, but Oracle complains

Just a note, we're using 11g, and I have no choice. I'm looking through all_constraints and trying to check the search_condition column, something like this: select * from all_constraints where table_name = UPPER('STVTERM') AND …
John O
  • 4,863
  • 8
  • 45
  • 78
3
votes
1 answer

How to test scale constraint in grails

In Grails domain class i have Field BigDecimal grossWeight and constraint for it static constraints = { grossWeight(nullable: true, min: BigDecimal.ZERO, scale: 3) } I like to have test for scale constraint but don't know how to…
Aram Arabyan
  • 2,339
  • 1
  • 17
  • 30