constraints

Removing All Primary Keys

This is going to sound like a crazy request. The databases that I report from do not have any foreign keys, and every single primary key is an identity_column. This makes using tools such as TOAD difficult because the Intellisense works by reading the PK and FK relationships. Anyone have a script to remove the primary keys from every t...

How to delete a record when two tables have foreign key referenced to each other?

Delete any record of them will report an error like this: ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails How to overcome this problem? ...

Creating SQL Server 2008 Constraint

I have a table with two integer columns and a bit column. How can I put a constraint on the table so that it will not allow duplicates with the combination of two integers with a true. For example: 1 2 True 1 2 False 1 2 True ------> This should not be allowed ...

null values in mySQL

I've got a new website moved to my server. This website uses PHP and MySQL, and is built very poorly. The problem is - it needs non-null values inserted into new records where ever I don't specify a value, though the default value is null. I've been told it has been done on the previous server, but they have no idea how. I'd be glad t...

Oracle DDL in autonomous transaction

I need to execute a bunch of (up to ~1000000) sql statements on an Oracle database. These statements should result in a referentially consistent state at the end, and all the statements should be rolled back if an error occurs. These statements do not come in a referential order. So if foreign key constraints are enabled, one of the stat...

insert several row in order to satisfy a constraint

hello, I have two table: deck(id) and card(deck,color,value) deck have those constraints: CHECK (fifty_two_cards_deck(id)) PRIMARY KEY (id) CREATE FUNCTION fifty_two_cards_deck(deck integer) RETURNS boolean LANGUAGE sql STABLE STRICT AS $_$ SELECT COUNT(*)=52 FROM card WHERE deck=$1 $_$; and card have those constraints: ...

NSPredicate as a constraint solver?

I'm working on a project which includes some slightly more complex dynamic layout of interface elements than what I'm used to. I always feel stupid writing complex code that checks if so-and-so is close to such-and-such and in that case move it x% in some direction, etc. That's just not how programming should be done. Programming should ...

Continuing a transaction after primary key violation error

I am doing a bulk insert of records into a database from a log file. Occasionally (~1 row out of every thousand) one of the rows violates the primary key and causes the transaction to fail. Currently, the user has to manually go through the file that caused the failure and remove the offending row before attempting to re-import. Given th...

Composite Primary keys and Foreign key constraint error

Hi, I have an SQL table defined as below: CREATE TABLE [TestComposite] ( ID int, SiteUrl nvarchar(255), Name nvarchar(max) NOT NULL, ParentID int NULL, PRIMARY KEY (ID, SiteUrl) ); Items and folders are stored inside the same table, if an item is inside a folder, the ParentID column is the ID of the ...

Finding ghost constraint from Oracle DB

I had a constraint in a table CREATE TABLE "USERSAPPLICATIONS" ( "USERID" NUMBER NOT NULL , "APPLICATIONNAME" VARCHAR2 (30) NOT NULL , CONSTRAINT "PK_USERSAPPLICATIONS" PRIMARY KEY ("USERID","APPLICATIONNAME") ) / Two weeks ago I modified the table, added some columns, deleted the constraint "PK_USERSAPPLICATIONS" and add...

Fluent NHibernate Automapping DDL is missing foreign key reference column

I've created the following classes and use the automap functionality of fluent to automatically generate my database: public interface IBaseClass { int Id { get; set; } DateTime CreatedOn { get; set; } } public interface IApplicant : IBaseClass { string Firstname { get; set; } string Lastnam...

Restricting number of rows

I want to restrict the maximum possible rows that can be inserted in the table. Is it possible to have such constraint in database ? ...

How to dynamcially call a generic method based on a mapping in a dictionary?

I have a method String Foo<T> where T: WebControl Now I do have a string like "hyperlink". What is want is to call Foo<Hyperlink> based on a mapping from the string to the generic. How does the dictionary have to look like? It ain't: private Dictionary<string, Type> _mapping = new Dictionary<string, Type>() { {"hyperlink", ty...

C# generic constraints

Is it possible to enumerate which types that is "available" in a generic constraint? T MyMethod<t>() where T : int, double, string Why I want to do this is that I have a small evaluator engine and would like to write code like this: bool expression.Evaluate<bool>(); or int expression.Evaluate<int>(); but i want to prohibit MyC...

MYSQL Contraints - Multiple Checks

Well i am here writing some constraints for a db I am working on and i was wondering if I could do the following: ALTER TABLE Course ADD CONSTRAINT cs_level CHECK (clevel in ('P','I','II','III')) ...instead of this: ALTER TABLE Course ADD CONSTRAINT cs_level CHECK (clevel = 'P' OR clevel = 'I' OR clevel = 'II' OR clevel = 'III') ...

How to have a primary key combination that may have null values?

I have two tables A and B as defined bellow. create table A ( A_1 varchar2(10) NOT NULL, A_2 varchar2(10), A_3 varchar2(10), constraint A_PK primary key (A_1,A_2) ) TABLE A DATA A_1 |A_2 |A_3 1111 abc some_text1 1111 null some_text1 1112 abc some_text2 1113 def some_text3 create table B ...

How do you add a NOT NULL FOREIGN KEY column to an existing (populated) table in MS SQL?

I need to add a NOT NULL column to an existing (populated) table that will be a foreign key to another table. This brings about two problems: When you add the column, its value cannot be null - using a default is not an option (unless it is removed later on) because the database logic is used in the server side validation when a user e...

Relational Database (H2, Java): How do I constrain a foreign key to NOT match another foreign key in the same table?

Simple question. Just wondering if this can be done without me having to enforce this constraint manually in my Java code. These two foreign keys (together in the same table) both refer out to another table, but for each row, they must not be allowed to point to the same foreign item. link text ...

MS SQL Bridge Table Constraints

Greetings - I have a table of Articles and a table of Categories. An Article can be used in many Categories, so I have created a table of ArticleCategories like this: BridgeID int (PK) ArticleID int CategoryID int Now, I want to create constraints/relationships such that the ArticleID-CategoryID combinations are unique AND that th...

Passing Data by Route Constraint

Hy, in my Global.asax I've this rule: // Home routes.MapRoute("Home", "{lang}/", new { lang = "ita", controller = "Home", action = "Index" }, new { lang = new LanguageRouteConstraint() } ); And my LanguageRouteConstraint class: public class LanguageRouteCo...