constraints

Is a primary key automatically an index?

If I run Profiler, then it suggests a lot of indexes like this one CREATE CLUSTERED INDEX [_dta_index_Users_c_9_292912115__K1] ON [dbo].[Users] ( [UserId] ASC )WITH (SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF) ON [PRIMARY] UserId is the primary key of the table Users. Is this index better than the...

Search and Matching algorithm

I am trying to come up with an algorithm to do the following: I have total 12 cells that I need to fill until program stops. I have 3 rows and each row has 4 columns. As an example, let me illustrate this as in airplane. So you have 3 rows and each row has 4 columns and you have window/aisle seats. Each row will have a window seat, ais...

About sql server rules

How can I correct this syntax , create rule r1 as @ f <1000 ? ...

System.String - why doesn't it implement parameterless constructor?

Hi. I wanted to ask what is the idea behind the fact that System.String doesn't contain parameterless constructor. Because of this you cannot use this type when there is new() constraint. UPDATE Why do you think that new string() is useless and e.g. new int() is not useless. I really cannot see the difference. I really would like to ...

Variable field in a constraint annotation

Hello, I need to create a custom constraint annotation which can access the value of another field of my bean. I'll use this annotation to validate the field because it depends on the value of the other but the way I define it the compiler says "The value for annotation attribute" of my field "must be a constant expression". I've defin...

SQL CHECK constraint to prevent date overlap

I have a table that describes which software versions were installed on a machine at various times: machine_id::integer, version::text, datefrom::timestamp, dateto::timestamp I'd like to do a constraint to ensure that no date ranges overlap, i.e. it is not possible to have multiple software versions installed on a machine at the same ...

Calling assembly in GCC?

#include <stdlib.h> static inline uint xchg(volatile unsigned int *addr, unsigned int newval) { uint result; asm volatile("lock; xchgl %0, %1" : "+m" (*addr), "=a" (result) : "1" (newval) : "cc"); return result; } Can some one tell me what this code does exactly? I mean I have an idea or the parts of this command. "1" newva...

how can i set up a uniqueness constraint in mysql for columns that can be null?

I know that in MySQL, UNIQUE constraits don't treat NULL values as equal. So if I have a unique constraint on ColumnX, then two separate rows can have values of NULL for ColumnX and this wouldn't violate the constraint. How can I work around this? I can't just set the value to an arbitrary constant that I can flag, because ColumnX in m...

Constraint Satisfaction Problem

I'm struggling my way through Artificial Intelligence: A Modern Approach in order to alleviate my natural stupidity. In trying to solve some of the exercises, I've come up against the "Who Owns the Zebra" problem, Exercise 5.13 in Chapter 5. This has been a topic here on SO but the responses mostly addressed the question "how would you s...

MySQL ignores the NOT NULL constraint

I have created a table with NOT NULL constraints on some columns in MySQL. Then in PHP I wrote a script to insert data, with an insert query. When I omit one of the NOT NULL columns in this insert statement I would expect an error message from MySQL, and I would expect my script to fail. Instead, MySQL inserts empty strings in the NOT NU...

What's the default of ONDELETE and ONUPDATE for foreign keys in SQL?

My guess would be that a foreign key reference is set to RESTRICT by default. But, is there any standard for this? Is the default equal on any database type? Or should these values be defined in all statements just to be sure? ...

I'm looking for a constraint to prevent the insert of an empty string in MySQL

Ok, 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 something like a database constraint to prevent this. Of course a check on the application side is necessary, but I'd like it to be on both sid...

Having constrains object to move X,Y at the same time?

The stage is separated into 4 sections, and I will be moving the camera around the stage. So at each particular section the camera will have an area of constrain it can move. I mange to constrain its X & Y, but it could only navigate either X or Y. How to move in X+Y at the same time? if (mouseX>sec2maxX) { TweenLite.to(...

How can I drop a "not null" constraint in Oracle when I don't know the name of the constraint?

I have a database which has a NOT NULL constraint on a field, and I want to remove this constraint. The complicating factor is that this constraint has a system-defined name, and that constraint's name differs between the production server, integration server, and the various developer databases. Our current process is to check in chan...

How to make safe cast using generics in C#?

I want to implement a generic method on a generic class which would allow to cast safely, see example: public class Foo<T> : IEnumerable<T> { ... public IEnumerable<R> SafeCast<R>() where T : R { return this.Select(item => (R)item); } } However, the compiler tells me that Foo<T>.SafeCast<R>() does not d...

what really are database Constraints?

What really is constraints? Why i need to know about them? What are the types of constraints? ...

C# overloading with generics: bug or feature?

Let's have a following simplified example: void Foo<T>(IEnumerable<T> collection, params T[] items) { // ... } void Foo<C, T>(C collection, T item) where C : ICollection<T> { // ... } void Main() { Foo((IEnumerable<int>)new[] { 1 }, 2); } Compiler says: The type 'System.Collections.Generic.IEnumerable' cannot be...

Combining the UNIQUE and CHECK constraints

I have a table with columns a b and c, and if c is false then I only want to allow insertions if columns a and b are unique, but if c is true then a and b do not need to be unique. Example: There can only be one (foo, bar, false) in the table, but no limit on how many (foo, bar, true) there can be. I tried something like CONSTRAINT bla...

MySQL composite unique on FK's

I want to implement the following constraints in mysql: create table TypeMapping( ... constraint unique(server_id,type_id), constraint foreign key(server_id) references Server(id), constraint foreign key(type_id) references Type(id) ); This throws a 'ERROR 1062 (23000): Duplicate entry '3-4' for key 'server_id'' when...

Unable to drop constraint in sql server 2005 "Could not drop constraint. See previous errors"

I'm trying to drop a constraint on a db table, something like: ALTER TABLE MyTable drop CONSTRAINT FK_MyTable_AnotherTable But the execution just runs and runs. If I stop it I see: Msg 3727, Level 16, State 0, Line 2 Could not drop constraint. See previous errors. Web search throws up various pages but note that the constraint is p...