constraints

Delete all records that have no foreign key constraints

I have a SQL 2005 table with millions of rows in it that is being hit by users all day and night. This table is referenced by 20 or so other tables that have foreign key constraints. What I am needing to do on a regular basis is delete all records from this table where the "Active" field is set to false AND there are no other records in ...

Finding which table a constraint belongs to

Hi, I need to find out which table(name) a particular constraint belongs to. Does anyone have any TSQL to achieve this? ...

How to use constraint programming for optimizing shopping baskets?

I have a list of items I want to buy. The items are offered by different shops and different prices. The shops have individual delivery costs. I'm looking for an optimal shopping strategy (and a java library supporting it) to purchase all of the items with a minimal total price. Example: Item1 is offered at Shop1 for $100, at Shop2 fo...

In generated code, how to access the facets declared in the XSD file ?

Hi, What I thought was going to be a simple problem turns out to be quite a head scratcher. I am currently using JAXB 2 to generate code from an XSD on which I have no control. I need to access the constraints from the schemas so I can apply some logic and guard code when setting values in these objects. Validation in bulk simply will...

is there a less bloated way to test constraints in grails?

Is there a less bloated way to test constraints? It seems to me that this is too much code to test constraints. class BlogPostTests extends GrailsUnitTestCase { protected void setUp() { super.setUp() mockDomain BlogPost } void testConstraints() { BlogPost blogPost = new BlogPost(title: "", text: "")...

Temporarily disable constraints (Sybase)

Is there the way to temporarily disable checking of foreign keys, check constraints and rules for some table in Sybase? ...

T-SQL foreign key check constraint

When you create a foreign key constraint in a table and you create the script in MS SQL Management Studio, it looks like this. ALTER TABLE T1 WITH CHECK ADD CONSTRAINT FK_T1 FOREIGN KEY(project_id) REFERENCES T2 (project_id) GO ALTER TABLE T1 CHECK CONSTRAINT FK_T1 GO What I don't understand is what purpose has the second alter with...

Can I constrain a route parameter to a certain type in ASP.net MVC?

I have the following route: routes.MapRoute( "Search", // Route name "Search/{affiliateId}", // URL with parameters new { controller = "Syndication", action = "Search" } // Parameter defaults ); Is there a way I can ensure "affiliateId" is a va...

Is it Possible to Use Constraints on Hierarchical Data in a Self-Referential Table?

Suppose you have the following table, intended to represent hierarchical data: +--------+-------------+ | Field | Type | +--------+-------------+ | id | int(10) | | parent | int(10) | | name | varchar(45) | +--------+-------------+ The table is self-referential in that the parent_id refers to id. So you might ha...

How to constrain a table linking two tables in many-to-many relationship

Say I have the following tables and columns: comp: id, model dvd: id, model comp2dvd: id, id_comp, id_dvd A computer can have multiple dvd drives, even of the same model, and a dvd drive can appear in multiple computers. How do I make it so that comp2dvd table can have only existing comp and dvd id...

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 (1) or (2) above I have come up with the following code, which works fine for cases (1) and (2): static void Foo<T>(T a) where T : stru...

limiting sql server constraint checks to only new data

I need to import a lot of data into a sql server database. Some of this data was imported from long ago and much of it does not maintain referential integrity but I want all new data to. I can turn off the constraint checks prior to the import but how do it turn them back on only for data that will be added later? Is this possible or do ...

Grails' GORM constraint question

Hi, I have the following Domain Class: class Metric { String name float value static belongsTo = [Person,Corporation] static indexes = { name() } } How can I add a constraint so Person,Corporation and name are unique ? Thanks. ...

In VB.NET how do you specify Inherits/implements on a generic class with multi-constraints

When I write the following statement in VB.Net (C# is my normal language), I get an "end of statement expected" referring to the "Implements" statement. <Serializable()> _ <XmlSchemaProvider("EtgSchema")> _ Public Class SerializeableEntity(Of T As {Class, ISerializable, New}) _ Implements IXmlSerializable, ISerializable ... End Class ...

Multiple keys/indeces/constraints when joining three tables

I'm getting more and more confused as I try to distinguish from the ambiguities of these terms. I have a query that is taking longer than necessary simply because I cannot get the key on on table to work for the other joins. I have only one column that is "Unique" in t1, there are others which are 73.8% unique and I cannot figure out h...

Why is TRest in Tuple<T1... TRest> not constrained?

In a Tuple, if you have more than 7 items, you can provide an 8th item that is another tuple and define up to 7 items, and then another tuple as the 8th and on and on down the line. However, there is no constraint on the 8th item at compile time. For example, this is legal code for the compiler: var tuple = new Tuple<int, int, int, int...

Can I create a table with check constrain whose values are dependent on sql query

Is it possible to create a table which has a check constraint on one of the column whose value lies within the result set given by another sql query eg. create table tablename ( name varchar(10), rollno int )check rollno in (select rollno from anotherDatabase.TableName,candidateRoll) or any thing like that. I dont have to use it an...

I need to remove a unique constraints that I don't know the names of

I maintain a product that is installed at multiple locations which as been haphazardly upgraded. Unique constraints were added to a number of tables, but I have no idea what the names are at any particular instance. What I do know is the table/columnname pair that has the unique constraints and I would like to write a script to delete an...

T-SQL Unique constraint locked the SQL server

HI ! This is my table: CREATE TABLE [ORG].[MyTable]( .. [my_column2] UNIQUEIDENTIFIER NOT NULL CONSTRAINT FK_C1 REFERENCES ORG.MyTable2 (my_column2), [my_column3] INT NOT NULL CONSTRAINT FK_C2 REFERENCES ORG.MyTable3 (my_column3) .. ) I've written this constraint to assure that combination my_column2 and my_c...

List of Constraints from MySQL Database

How do I get a list of all constraints from a particular database? ...