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.

293
votes
18answers
85k views

Is there a constraint that restricts my generic method to numeric types?

Can anyone tell me if there is a way with generics to limit a generic type argument T to only:Int16Int32Int64UInt16UInt32UInt64I'm aware of the where keyword, but can't find an interface for ...
146
votes
9answers
93k views

Foreign key constraint may cause cycles or multiple cascade paths?

I have a problem when I try to add constraints to my tables. I get the error:Introducing FOREIGN KEY constraint 'FK74988DB24B3C886' on table 'Employee' may cause cycles or multiple cascade paths. ...
735
votes
15answers
511k views

How can foreign key constraints be temporarily disabled using T-SQL?

Are disabling and enabling foreign key constraints supported in SQL Server? Or is my only option to drop and then re-create the constraints?
73
votes
5answers
91k views

“Insert if not exists” statement in SQLite

I have an SQLite database. I am trying to insert values (users_id, lessoninfo_id) in table bookmarks, only if both do not exist before in a row.INSERT INTO bookmarks(users_id,lessoninfo_id) VALUES(...
74
votes
4answers
81k views

UIScrollView doesn't use autolayout constraints

I have a scroll view and an image view behind it and I am populating it with nibs. I am using autolayout. I have a bottom space to superview and a top space to superview on both of the views. The ...
31
votes
3answers
12k views

Solution for overloaded operator constraint in .NET generics

What would I do if I want to have a generic method that only accepts types that have overloaded an operator, for instance the subtraction operator. I tried using an interface as a constraint but ...
184
votes
6answers
116k views

Unique Key constraints for multiple columns in Entity Framework

I'm using Entity Framework 5.0 Code First;public class Entity{[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]public string EntityId { get; set;}public int FirstColumn { get;...
5
votes
6answers
38k views

Using date in a check constraint, Oracle

I am trying to check add the following constraint but Oracle returns the error shown below.ALTER TABLE Table1ADD (CONSTRAINT GT_Table1_CloseDateCHECK (CloseDate > SYSDATE),CONSTRAINT ...
42
votes
2answers
17k views

Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5

I understand the old Struts and Springs method of aligning, sizing and distributing views in Interface Builder. However, I cannot seem to figure out how to evenly distribute views using auto layout ...
180
votes
10answers
180k views

SQL Server 2005 How Create a Unique Constraint?

How do I create a unique constraint on an existing table in SQL Server 2005?I am looking for both the TSQL and how to do it in the Database Diagram.
41
votes
6answers
41k views

Generic constraints, where T : struct and where T : class

I would like to differentiate between following cases:A plain value type (e.g. int)A nullable value type (e.g. int?)A reference type (e.g. string) - optionally, I would not care if this mapped to (...
89
votes
4answers
86k views

How to create a unique index on a NULL column?

I am using SQL Server 2005. I want to constrain the values in a column to be unique, while allowing NULLS.My current solution involves a unique index on a view like so:CREATE VIEW vw_unq WITH ...
174
votes
5answers
252k views

Turn off constraints temporarily (MS SQL)

I'm looking for a way to temporarily turn off all DB's constraints (eg table relationships).I need to copy (using INSERTs) one DB's tables to another DB.I know I can achieve that by executing ...
83
votes
6answers
144k views

Creating layout constraints programmatically

I know that a lot people already asked tons of questions about this, but even with the answers I can't make it work.When I'm dealing with constraints on storyboard, it's easy but in code I have a ...
51
votes
9answers
31k views

Template Constraints C++

In C# we can define a generic type that imposes constraints on the types that can be used as the generic parameter. The following example illustrates the usage of generic constraints:interface IFoo{...
28
votes
4answers
36k views

How do I add a check constraint to a table?

I am having trouble with this tableCREATE TABLE `Participants` (`meetid` int(11) NOT NULL,`pid` varchar(15) NOT NULL,`status` char(1) DEFAULT NULL,PRIMARY KEY (`meetid`,`pid`),...
116
votes
3answers
45k views

Unique constraint that allows empty values in MySQL

I have a field that stores product codes. The codes are unique, but some products simply doesn't have a code. I can't invent codes because those are providers codes.Is this kind of constraint ...
7
votes
3answers
2k views

Preventing adjacent/overlapping entries with EXCLUDE in PostgreSQL

I am creating a database which stores arbitrary date/time ranges in PostgreSQL 9.2.4. I want to place a constraint on this database which forces the date/time ranges to be non-overlapping, and non-...
40
votes
4answers
52k views

How to Create layout constraints programmatically

I am displaying a view in the bottom of the universal application and adding this view dynamically in my view. I want to show this view in bottom every time like iAd. in both orientation. How can I ...
21
votes
8answers
17k views

Is there a C# generic constraint for “real number” types? [duplicate]

Possible Duplicate:C# generic constraint for only integers Greets!I'm attempting to set up a Cartesian coordinate system in C#, but I don't want to restrict myself to any one numerical type ...
12
votes
2answers
13k views

Constraint defined DEFERRABLE INITIALLY IMMEDIATE is still DEFERRED?

In connection with this answer I stumbled upon a phenomenon I cannot explain.Version:PostgreSQL 9.1.2 on x86_64-unknown-linux-gnu, compiled by gcc-4.4.real (Debian 4.4.5-8) 4.4.5, 64-bitConsider ...
4
votes
1answer
2k views

UIScrollView and Constraints

I'm trying to place a UIImageView at the top of a UIScrollView and when I constrain the UIScrollView to the sides of the View Controller and constrain the UIImageView to the top and make the width of ...
4
votes
2answers
786 views

NOT NULL constraint over a set of columns

I have a table in Postgres which currently has a NOT NULL constraint on it's email column. This table also has a phone column which is optional. I would like the system to accept some records without ...
168
votes
4answers
68k views

How to trap on UIViewAlertForUnsatisfiableConstraints?

I'm seeing an error appear in my debugger log:Will attempt to recover by breaking constraint <NSLayoutConstraint:0x191f0920 H:[MPKnockoutButton:0x17a876b0]-(34)-[MPDetailSlider:0x17a8bc50](LTR)&...
43
votes
4answers
12k views

Why can't I use a type argument in a type parameter with multiple bounds?

So, I understand that the following doesn't work, but why doesn't it work?interface Adapter<E> {}class Adaptulator<I> {<E, A extends I & Adapter<E>> void add(Class&...
28
votes
6answers
17k views

What is the purpose of constraint naming

What is the purpose of naming your constraints (unique, primary key, foreign key)?Say I have a table which is using natural keys as a primary key:CREATE TABLE Order(LoginName VARCHAR(...
29
votes
2answers
17k views

A constraint to prevent the insert of an empty string in MySQL

In this question I learned how to prevent the insert of a NULL value. But, unfortunately, an empty string is being inserted anyway. Apart from preventing this on the PHP side, I'd like to use ...
10
votes
3answers
10k views

Can a MySQL trigger simulate a CHECK constraint?

I want to use the CHECK constraint in MySQL, but it is not supported. (Unlike other RDBMS, it will understand but not enforce the CHECKs.)I have seen some workarounds with triggers. But they tend to ...
469
votes
8answers
325k views

How to truncate a foreign key constrained table?

Why doesn't a TRUNCATE on mygroup work?Even though I have ON DELETE CASCADE SET I get:ERROR 1701 (42000): Cannot truncate a table referenced in a foreign key constraint (mytest.instance, ...
134
votes
10answers
89k views

How can I use interface as a C# generic type constraint?

Is there a way to get the following function declaration?public bool Foo<T>() where T : interface;ie. where T is an interface type (similar to where T : class, and struct).Currently I've ...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,