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

Creating Relationships between MySql tables

Im trying to create relationships between four tables in MySql: mainnodes (ID) subnodes (ID) tagrelationship (NODEID & TAGID) tag (ID) The table 'tagrelationship' references 'mainnodes' so when I try an insert, I can choose records from the…
Rob Fyffe
  • 719
  • 1
  • 8
  • 22
2
votes
1 answer

Control input of SQLite attribute to date format only.

I have been reading all about converting TEXT fields into date formats and ways to use Python to create date objects but my question remains. My table has a dateTime column that is specified as TEXT, I would like to build a constraint that forces…
Lolli
  • 21
  • 3
2
votes
1 answer

Simple check constraint not showing up properly in INFORMATION_SCHEMA.CHECK_CONSTRAINTS

I have a fairly simple check constraint, where I want to force two columns to be either both NULL or both NOT NULL. However INFORMATION_SCHEMA.CHECK_CONSTRAINTS does not properly show this constraint. I basically want this constraint: ((Col1 IS…
KM.
  • 101,727
  • 34
  • 178
  • 212
2
votes
1 answer

Datamodeling, constraints and issue with my model

I am designing an application that will allow for childminders/nannies to find babies to look after and parents to find childminders/nannies that will look after their children. I would like to have a single ACCOUNT database table both for parents…
balteo
  • 23,602
  • 63
  • 219
  • 412
2
votes
3 answers

SQL (oracle) Check Constraint difficulty - Not sure how to implement

I am creating a small database for a telecom system. One of the tables (calls) requires that a if a phone number's area code is not contained in a predefined list, then the number should not be added to the table. The way I have thought about…
JD87
  • 123
  • 2
  • 3
  • 9
2
votes
2 answers

Symfony2 fixtures with references not loading (constraint violation)

I've been struggling for several hours on my Symfony2 project fixtures. Here is the error I get : SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`wpanel_dev`.`sshuser`,…
2
votes
2 answers

How To Put A Constraint On Relationships In A Domain Class, In Grails?

I have a domain three domain class like this : Tasks.groovy class Tasks { static belongsTo = [ user : User ] //other fields Date startDate Date endDate } User.groovy class User { //relationships. . . . static belongsTo =…
Ant's
  • 13,545
  • 27
  • 98
  • 148
2
votes
2 answers

Constraint Violation Handling in Winforms Using NHibernate

I would like to handle the case where a user is editing an object from a database in a Windows Forms application, makes an edit that would violate a database constraint (i.e. column unique value), saves the entity back to the database, and…
2
votes
3 answers

SQL Constraint Check or a Trigger?

I've been searching the net for some answer to this. but all I get is the simple answers. I have a few columns in my database that should have a constraint on their maximum value but not if another column is set to false eg. I have the following…
Raskaroth
  • 639
  • 1
  • 9
  • 25
2
votes
2 answers

How to express constraints between members using templates?

Say I have a struct with a bunch of members: struct foo { int len; bar *stuff; }; As it so happens stuff will point to an array of bars that is len long. I'd like to encode this in stuff's type. So something like: struct foo { int len; …
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
2
votes
3 answers

How do you create an auto-incrementing revision number unique to a key in PGSQL?

Assuming I have the following tables. PARENT: PARENT_ID serial, DESCRIPTION character varying(50) CHILD: PARENT_ID integer, CHILD_ID integer, DESCRIPTION character varying(50) What I would like to see is each row in CHILD having a CHILD_ID that…
Some Canuck
  • 846
  • 7
  • 13
2
votes
3 answers

Deleting rows with column that references the same table takes bizzare amount of time

Sorry for a pretty specific question. I have a table (see bottom), and when I try to delete a lot of records from it, my PostgreSQL 8.2.5 spends 98% of the time doing the parent-child constraint. I'm trying to figure out what index should I add to…
alamar
  • 18,729
  • 4
  • 64
  • 97
2
votes
1 answer

Type Parameter Constraints - no generics (or nearest offer!)

I am thinking what I want to do is impossible but thought I would ask anyway. I am thinking of implementing some kind of custom conversion between different metric measurements - such as converting inches to metres and other units. I am thinking…
Andez
  • 5,588
  • 20
  • 75
  • 116
2
votes
3 answers

Constraints on Dijit DateTextBox [Valid days of the week]

Quick question about the Dijit.Form.DateTextBox http://docs.dojocampus.org/dijit/form/DateTextBox This page contains the following: "also validates against developer-provided constraints like min, max, valid days of the week, etc." I can't seem to…
Chase
2
votes
2 answers

Error message when dropping constrain

Every time I want to drop a constraint from a column I get an error. I can't see the problem. I am using postgres. So I have created a table with two columns: CREATE TABLE TableA( person_id INT PRIMARY KEY, lastname CHAR(100) ) I use the code ALTER…
1 2 3
99
100