constraints

What is wrong with my Oracle 10gr2 check constraint? Trying to enforce a date range

I want to enforce CHECK constraint on a date range such that all dates in column BIRTH_DATE are less than tomorrow and greater than or equal to 100 years ago. I tried this expression in a CHECK constraint: BIRTH_DATE >= (sysdate - numtoyminterval(100, 'YEAR')) AND BIRTH_DATE < sysdate + 1 But I received the error "ORA-02436: date or ...

Can you use "where" to require an attribute in c#?

I want to make a generic class that accepts only serializable classes, can it be done with the where constraint? The concept I'm looking for is this: public class MyClass<T> where T : //[is serializable/has the serializable attribute] ...

What's the difference between creating a UNIQUE index as "index" or as "constraint" in SQL Server?

When creating an index over a column that is going to be UNIQUE (but not the primary key of the table), SQL server let's me choose a few options: 1) I can choose for it to be a Constraint or an Index. I'm guessing this means that if I set it as constraint, it won't use it when querying, only when writing. However, the only efficient way...

How To Create A 'Two-Sided' Unique Index On Two Fields?

How can I efficiently create a unique index on two fields in a table like this: create table t (a integer, b integer); where any unique combination of two different numbers cannot appear more than once on the same row in the table. In order words if a row exists such that a=1 and b=2, another row cannot exist where a=2 and b=1 or a=1 a...

Generic contraints on derived classes

I have class A: public class ClassA<T> Class B derives from A: public class ClassB : ClassA<ClassB> Class C derives from class B: public class ClassC : ClassB Now I have a generic method with constraints public static T Method<T>() where T : ClassA<T> OK, now I want to call: ClassC c = Method<ClassC>(); but I get the compi...

SQL Deletion Cascading Help (Specific Question)

I have two tables (renamed/refactored for illustrative purposes) with a Many-To-Many relationship in an HSQL database. I want everything to be wiped out when I delete from one side of a Many-to-Many relationship (without querying the table; this is performance critical) Here are my main tables: CREATE TABLE PERSON ( PERSON_ID INTE...

Constraint vs. Validation?

I am working with Windows Forms Databinding, implementing interfaces like IDataErrorInfo. In order for this to work, the domain(or business) object is allowed to be in an invalid state. In fact, the domain object needs to retain the invalid value as the user entered it for IDataErrorInfo to work properly. As long as the object isn't p...

Oracle Check Constraint

I've been struggling with this check constraint for a few hours and was hoping someone would be kind enough to explain why this check constraint isn't doing what I think it should be doing. ALTER TABLE CLIENTS add CONSTRAINT CHK_DISABILITY_INCOME_TYPE_ID CHECK ((IS_DISABLED IS NULL AND DISABILITY_INCOME_TYPE_ID IS NULL) OR (IS_DISABLED ...

MySQL terminology "constraints" vs "foreign keys" difference?

I'm looking at the MySQL docs here and trying to sort out the distinction between FOREIGN KEYs and CONSTRAINTs. I thought an FK was a constraint, but the docs seem to talk about them like they're separate things. The syntax for creating an FK is (in part)... [CONSTRAINT [symbol]] FOREIGN KEY [index_name] (index_col_name, ...) R...

MySQL -- create two indexes, only one appears in SHOW CREATE TABLE output

In have a many-to-many linking table and I'm trying to set up two foreign keys on it. I run these two statements: ALTER TABLE address_list_memberships ADD CONSTRAINT fk_address_list_memberships_address_id FOREIGN KEY index_address_id (address_id) REFERENCES addresses (id); ALTER TABLE address_list_memberships ADD CONSTRAINT fk_address_...

How do I get constraint details from the name in Informix?

When programming a large transaction (lots of inserts, deletes, updates) and thereby violating a constraint in Informix (v10, but should apply to other versions too) I get a not very helpful message saying, for example, I violated constraint r190_710. How can I find out which table(s) and key(s) are covered by a certain constraint I know...

SQL Server Transactional Replication, and different primary keys

With SQL Server 2005 and transactional replication, can I remove the primary key constraints on the subscriber, while leaving the primary key constraints on the publisher? Primary I want to do this because I want to cluster on different columns than the existing clustered constraints. I don't think I can convert a constraint from clust...

Can I check for constraints before a delete in SQL Server?

I have following situation. A main table and many other tables linked together with foreign keys. Now when I would like to delete a row in the main table a ConstraintsViolation will occur, which is intended and good. Now I want to be able to check if the ConstraintsViolation will occur before I trigger the delete row event. Is this po...

Is there a way to avoid row deletion on an specific table using constrains or triggers?

Is there a way to avoid row deletion on an specific table using constrains? I'd like to (for example) deny row deletion if the id is 0,1 or 2 This is in order to avoid users deleting master accounts for an application, and I'd like to avoid it even if someone tries it (by mistake) using sql directly. Thanks! EDIT: The whole idea of ...

How important are constraints like NOT NULL and FOREIGN KEY if I'll always control my database input with PHP?

I am trying to create a column in a table that's a foreign key, but in MySQL that's more difficult than it should be. It would require me to go back and make certain changes to an already-in-use table. So I wonder, how necessary is it for MySQL to be sure that a certain value is appropriate? Couldn't I just do that with a language li...

Should I check for DB constraints in code or should I catch exceptions thrown by DB

Hi, I have an application that saves data into a table called Jobs. The Jobs table has a column called Name which has a UNIQUE constraint. The Name column is not PRIMARY KEY. I wonder if I should check for duplicate entries myself before I try to save/update a new entry or if it's better to wait for an exception thrown by the data acces...

Is there a way to enable / disable constraints in db2 v7?

Hello people, I have to copy tables from an Oracle database to a db2 v7 one, and in order to do this (avoiding millions of drops and creates) I'd like to know if db2 has a feature like Oracle to enable / disable constraints temporarily without dropping them. Thanks in advance, Mauro. ...

How to best enforce single-level recursion in a SQL table?

Let's say you have a table for branches in your organization. Some of them are "main" branches, and others are satellite offices that roll up to a main branch. Other than this distinction, which only impacts a few things in the system, the branches are all peers and have the same attributes (address, etc.). One way to model this is in a ...

Using Triggers To Enforce Constraints

I'm trying to enforce integrity on a table in a way which I do not think a Constraint can... CREATE TABLE myData ( id INTEGER IDENTITY(1,1) NOT NULL, fk_item_id INTEGER NOT NULL, valid_from DATETIME NOT NULL, invlaid_from DATETIME NOT NULL ) The constraint I wan...

How can fields in Grails represented by a combobox be made optional?

I'm doing my first experiments with Grails and am looking for a way to have fields represented by a combobox (such as one-to-one domain associations and numbers with a narrow range constraint) to be optional, i.e. there should be an empty entry in the combobox. How can this be achieved? I've tried both adding a nullable:true constraint ...