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

Existence of a permutation under constraints (Interview Street - Manipulative Numbers)

I am trying to solve this problem: https://www.interviewstreet.com/challenges/dashboard/#problem/4f9a33ec1b8ea Suppose that A is a list of n numbers ( A1, A2, A3, ... , An) and B ( B1, B2, B3, .. ,Bn ) is a permutation of these numbers. We say B is…
3
votes
2 answers

ORM and Database Constraints

How compatible is ORM and existing databases that have a lot of constraints (particularly unique key constraints/unique indexes beyond primary keys) enforced within the database itself? (Often these are preexisting databases, shared by numerous…
Jason Kresowaty
  • 16,105
  • 9
  • 57
  • 84
3
votes
1 answer

MSSQL merge replication Automatic Identity Range Management

I have set up an MSSQL merge replication on a large database. One of the tables has 1.5 billion records and causes the snapshot agent to timeout on this table. So first I exported the data of the table to a .csv file, truncated the table and then…
3
votes
1 answer

Drag an image within a div with left/right constraints

I'm trying to nest an image in a div and make it draggable on the X axis within this div. Here's a jsFiddle to illustrate my point I'd like the blue box to stop dragging once the user reaches its left/right edges, he shouldn't be able to see any of…
morgi
  • 1,005
  • 3
  • 17
  • 24
3
votes
2 answers

Setting constraint for two unique fields in PostgreSQL

I'm new to postgres. I wonder, what is a PostgreSQL way to set a constraint for a couple of unique values (so that each pair would be unique). Should I create an INDEX for bar and baz fields? CREATE UNIQUE INDEX foo ON table_name(bar, baz); If not,…
John Doe
  • 9,414
  • 13
  • 50
  • 69
3
votes
1 answer

Get row to swap tables on a certain condition

I currently have a parent table: CREATE TABLE members ( member_id SERIAL NOT NULL, UNIQUE, PRIMARY KEY first_name varchar(20) last_name varchar(20) address address (composite type) contact_numbers varchar(11)[3] date_joined…
Danny Calladine
  • 321
  • 1
  • 2
  • 13
3
votes
2 answers

rows that violate unique constraints

I have a postgres 8.3.4 database. A name table exists with a unique constraint on the triplet UNIQ(name, id, age). Somehow there are several rows that have been added to the database that cause violation of this constraint. My question is how is…
Finslicer
  • 868
  • 8
  • 8
3
votes
4 answers

How to constrain tags between 3 tables

I'm working on a tags system, what it should do is you can have a query and selected tags, e.g. jquery and tags of javascript, library. It should only show related scripts with the query AND only that have the tags. This is the database…
MacMac
  • 34,294
  • 55
  • 151
  • 222
3
votes
1 answer

Conditional constraint unique

I have next table create table use_flags3 ( id INTEGER, flag_name VARCHAR NOT NULL, flag_description VARCHAR NOT NULL, flag_type_id INTEGER NOT NULL, package_id INTEGER, FOREIGN KEY (flag_type_id) REFERENCES…
ZuBB
  • 124
  • 2
  • 8
3
votes
2 answers

Minimize complex linear multivariable function in java

I need to minimize a complex linear multivariable function under some constraints. Let x be an array of complex numbers of length L. a[0], a[1], ..., a[L-1] are complex coefficients and F is the complex function F(x)= x[0]*a[0] + x[1]*a[1] + ... +…
3
votes
4 answers

Validating UPDATE and INSERT statements against an entire table

I'm looking for the best way to go about adding a constraint to a table that is effectively a unique index on the relationship between the record and the rest of the records in that table. Imagine the following table describing the patrols of…
David
  • 24,700
  • 8
  • 63
  • 83
3
votes
2 answers

Overriding the maximum value of a bigint datatype in SQL Server

Could a database administrator override the largest value that a bigint datatype could hold (making it smaller than what is listed in the documentation)?
Elliott
  • 5,523
  • 10
  • 48
  • 87
2
votes
3 answers

"SQLSTATE[23000]: Integrity constraint violation" with valid constraint

I'm using Symfony 2 with Doctrine. I have 4 classes: Country, District, County and Local. District has a foreign key of Country; County has a foreign of District; Local has a foreign key of District. The problem is that when inserting a County…
Miguel Ribeiro
  • 8,057
  • 20
  • 51
  • 74
2
votes
1 answer

MSSQL - replication and Violation of PK constraint

I've setup a transactional replication and allowed initialize from backup due to bandwidth restraints (so no snapshots generated). Now we get this error on the Publication database, when the application that inserts data in the database is started…
2
votes
2 answers

In Eclipse, how can I show generic type constraints in Javadocs?

In Eclipse, when you hover on an element, only the Javadoc shows, and the element's (unconstrained) signature. Suppose I have a class X {}. If I use Eclipse's Javadoc generator, I get: /** * @param */ The rendered…
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246
1 2 3
99
100