constraints

SQL 2005: Keys, Indexes and Constraints Questions

I have a series of questions about Keys, Indexes and Constraints in SQL, SQL 2005 in particular. I have been working with SQL for about 4 years but I have never been able to get definitive answers on this topic and there is always contradictory info on blog posts, etc. Most of the time tables I create and use just have an Identity colu...

Check constraint on table lookup

Hi, I have a table, department , with several bit fields to indicate department types One is Warehouse (when true, indicate the department is warehouse) And I have another table, ManagersForWarehouses with following structure: ID autoinc WarehouseID int (foreign key reference DepartmentID from departments) ManagerID int (foreign key r...

Is it possible to constrain a table to have a value in only one of a set of columns

I have a table which needs to link one of three seperate tables, but it should only link to one of them, e.g. Main_Table id UNIQUEIDENTIFIER t1_id UNIQUEIDENTIFIER t2_id INT t3_id INT T1 id UNIQUEIDENTIFIER name VARCHAR(255) T2 id INT name VARCHAR(255) T3 id INT name VARCHAR(255) Is it possible to have a constraint whereby only one...

How do I change constraints in a dojo DateTextBox dynamically?

I tried to do this: dojo.mixin(endDate.constraints, {min: new Date(2009,09,14)}); But as a result I got this: min Wed Oct 14 2009 00:00:00 GMT+0200 (CET) ??? It always adds one month! Is this a bug? But what I actually want to do is something like this: dojo.mixin(endDate.constraints, {min: dijit.byId("beginDate").date}); Th...

Sql Server 2008 check constraint

I have two tables, Table1 and Table2 with same primary key (FKTestID). If I want to delete one row in Table1 and same FKTestID are in Table2 it will not work. You can only delete a row from Table1 if Table1.FKTestID not equals any FKTestID in Table2. Please help me with this constraint? ...

Graphwiz: Is there a way to force a node to the bottom?

I'm building a CFG, and I'd like the exit node to always be at the bottom of the graph. Sometimes it happens naturally, sometimes it doesn't. Example: digraph G { 0; 1; 4; 5; 7; 8; 0 -> 4; 5 -> 7; 7 -> 8; 7 -> 1; 8 -> 5; 4 -> 7; } Draws (using dot): Node 1 is my exit node, I'd like that to be at the bottom....

implementing UNIQUE across linked tables in MySQL

a USER is a PERSON and a PERSON has a COMPANY - user -> person is one-to-one, person -> company is many-to-one. person_id is FK in USER table. company_id is FK in PERSON table. A PERSON may not be a USER, but a USER is always a PERSON. If company_id was in user table, I could create a unique key based on username and company_id, but i...

Check constraint with only one value SQL Server 2005

I have a table with these fields: User_id, User_type, User_address Is it possible to add a constraint where only one record can exist where user_type = 'xyz' per user_id? There can be as many user_type = 'abc' as we wish but only one 'xyz'. I know that this is not the greatest design but it is what is there currently and I need to l...

why can not add this foreign key?

I have this schema: CREATE TABLE `lotto`.`combinaciones` ( `indice` mediumint(8) unsigned NOT NULL, `binario` int(10) unsigned NOT NULL, PRIMARY KEY USING BTREE (`indice`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 CREATE TABLE `lotto`.`sorteo` ( `numeroSorteo` int(11) NOT NULL, `fechaSorteo` date NOT NULL, `precioCarton` doub...

At which stage does SqlBulkCopy check constraints?

If SqlBulkCopyOptions.CheckConstraints option is set for SqlBulkCopy insert, does it check the constraints separately after each record, or after all records are inserted? I have a check constraint that compares some columns to the parent row (through a UDF). I'm using MS Sql Server 2005. The documentation at http://msdn.microsoft.com/e...

Mysql mapping table FK constraints

Hi, I'm experiencing some difficulties with foreign key constraints. I have three tables: Features ID PK AUTO_INC Title VARCHAR Subscriptions ID PK AUTO_INC Title VARCHAR Subscriptionfeatures ID PK AUTO_INC feature_id INT (index) subscription_id INT (index) When I have the following records Features 1...

Compound UniqueConstraint with a function

Hi everyone! A quick SQLAlchemy question... I have a class "Document" with attributes "Number" and "Date". I need to ensure that there's no duplicated number for the same year, is there a way to have a UniqueConstraint on "Number + year(Date)"? Should I use a unique Index instead? How would I declare the functional part? (SQLAlchemy...

Django: apply "same parent" constraint to ManyToManyField mapping to self

I have a model where tasks are pieces of work that each may depend on some number of other tasks to complete before it can start. Tasks are grouped into jobs, and I want to disallow dependencies between jobs. This is the relevant subset of my model: class Job(models.Model): name = models.CharField(max_length=60, unique=True) class ...

Can I have composite constraints?

Hi, Having a table with this structure... Table_files id_file (PK) file_name file_path ... can I have a constraint that allows me to not duplicate the pair "file_name"+"file_path" (but allows me to duplicate the "file_name" and "file_path" individually), where the only Primary Key is the field "id_file"? Thanks ...

Order of calculation and iterations for physics engines

I'm writing a physics engine that uses Verlet integration, and i can't get some constraints to work right. Some (like a bond/weld constraint) are extra "soggy" and aren't stiff enough, while others (like an area constraint) are extra bouncy and send atoms flying. The code for my update ethod in my physics simulator is like this: Pr...

Hibernate constraint violation/error rolling back

I have encountered a strange error with hibernate, most likely due to improper use of it, but I was wondering if there is any way to find the root cause of it and perhaps remedy it. Currently I have a class hierarchy that looks like: @Entity @Inheritance(strategy = InheritanceType.JOINED) @Table(name = "tbl_class_a) public ClassA { ...

Area constraint blows up my physics simulation if a body slams into it too fast

I have a physics simulation and it allows you to place area constraints, so that the bodies within will not exit that area. However if an atom goes past one of the "walls" of the area constraint it blows up the physics simulation. Why does it do this? Update method: if (!atom.IsStatic) { Vector2 force = Vector2.Zero; bool x = fa...

Constraint Exception when copying table?

I'm experiencing some weird behavior when trying to modify some DataTable objects. Upon the second call to the subroutine, I get the following error when I to copy the source DataTable to a working set: System.Data.ConstraintException was caught Message="Column 'pk' is constrained to be unique. Value 'path0.tag0' is already...

Best practices in modelling user constraints in a webapp?

I'm building a webapp with role based access control using Acegi (Spring) security. So i have different users with roles: ROLE_ADMIN, ROLE_USER and etc. However, i need to implement various user constraints. Let's consider an example: Suppose, there is a site where users can watch movies online. There are users with roles ROLE_STA...

Algorithm for effective connection resource management

Hi, difficult to look this up if it has been asked previously since I don't know the name for it. So here goes: I'm making this server which connects to messaging gateways in order to send msgs. A session with this gateway requires a username/password combo. This way the gateway knows who to bill. Now I could have thousands of message...