constraints

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. ...

override constraint from no action to cascading at runtime

I feel like I have a verry basic/stupid question, yet I never saw/read/heard anything in this direction. Say I have a table users(userId, name) and a table preferences(id, userId, language). The example is trivial, but could be extended to a situation with multi-level relations and way more tables.. When my UI requests to delete a user ...

XML Serialize boolean as 0 and 1

Hello Everybody. The XML Schema Part 2 specifies that an instance of a datatype that is defined as boolean can have the following legal literals {true, false, 1, 0}. The following XML, for example, when deserialized, sets the boolean property "Emulate" to true. <root> <emulate>1</emulate> </root> However, when I serialize the obj...

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 { } class Foo<T> where T : IFoo { } class Bar : IFoo { } class Simpson { } class Program { static void Main(string[] args) { ...

How do I check that I removed required data only?

Hello. I have a really big database (running on PostgreSQL) containing a lot of tables with sophisticated relations between them (foreign keys, on delete cascade and so on). I need remove some data from a number of tables, but I'm not sure what amount of data will be really deleted from database due to cascade removals. How can I check...

Double generic constraint on class in Java: extends ConcreteClass & I

Is there a way to define a generic constraint in Java which would be analogous to the following C# generic constratint ? class Class1<I,T> where I : Interface1, Class2 : I I'm trying to do it like this: class Class1<I extends Interface1, T extands I & Class2> But the compiler complains about the "Class2" part: Type parameter cannot...

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 interfaces can't have operator overloading. What is the best way to achieve this? ...

Triggers vs Constraints

I'm trying to find out whether I should be using business critical logic in a trigger or constraint. So far I've added logic in triggers as it gives me the control over what happens next and means I can provide custom user messages instead of an error that will probably confuse the users. Is there any noticable performance gain in using...

How can I use a type with generic arguments as a constraint?

I would like to specify a constraint which is another type with a generic argument. class KeyFrame<T> { public float Time; public T Value; } // I want any kind of Keyframe to be accepted class Timeline<T> where T : Keyframe<*> { } But this cannot be done in c# as of yet, (and I really doubt it will ever be). Is there any eleg...

Can foreign key constraints be temporarily disabled using TSQL?

Are disabling and enabling FK constraints supported in SQL Server? Or is my only option to 'drop and then re-'create' the constraints? ...

How to constrain a database table so only one row can have a particular value in a column?

Using Oracle, if a column value can be 'YES' or 'NO' is it possible to constrain a table so that only one row can have a 'YES' value? I would rather redesign the table structure but this is not possible. [UDPATE] Sadly, null values are not allowed in this table. ...

What do the letter codes in Oracle user_contraints table's constraint_type column stand for?

select distinct constraint_type from user_constraints; C - C P R U Seems P means primary key and R means foreign key, correct? What are U and C? ...

Compiler fails converting a constrained generic type.

Hello, I have a class that has a Generic type "G" In my class model i have public class DetailElement : ElementDefinition Let's say i have a method like this public void DoSomething<G>(G generic) where G : ElementDefinition { if (generic is DetailElement) { ((Detai...

SQL Server 2000 constraint involving column on different table

I would like a constraint on a SQL Server 2000 table column that is sort of a combination of a foreign key and a check constraint. The value of my column must exist in the other table, but I am only concerned with values in the other table where one of its columns equal a specified value. The simplified tables are: import_table: part...

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 SCHEMABINDING AS SELECT Column1 FROM MyTable WHERE Column1 IS NOT NULL CREATE UNIQUE CLUSTERED INDEX unq_idx ON vw_unq (Column...

C# Generics wont allow Delegate Type Constraints

Is it possible to define a class in C# such that class GenericCollection<T> : SomeBaseCollection<T> where T : Delegate I couldn't for the life of me accomplish this last night in .NET 3.5. I tried using delegate, Delegate, Action<T> and Func<T, T> It seems to me that this should be allowable in some way. I'm trying to implement my o...

Oracle 10gr2: prevent any dates that fall on a Sunday?

Is it possible to use a CHECK constraint to prevent any date that falls on a Sunday? I don't want to use a trigger. ...

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 E>> void add(Class<E> extl, Class<A> intl) { addAdapterFactory(new AdapterFactory<E, A>(extl, intl)); } } The add() method gives me a compile error, "Cannot specify any additional bou...

Oracle 10gr2: enforce dates entered are between 9am and 5pm?

I want to enforce that date-times that are entered fall between 9am and 5pm. How do I enforce this with ORACLE CHECK constraints? ...

In SQL Server 2005, how do I set a column of integers to ensure values are greater than 0?

This is probably a simple answer but I can't find it. I have a table with a column of integers and I want to ensure that when a row is inserted that the value in this column is greater than zero. I could do this on the code side but thought it would be best to enforce it on the table. Thanks! I was in error with my last comment all i...