constraints

How to use an auto incremented primary key as a foreign key as well?

Hello This is what I'm trying to do: I have 2 tables... CREATE TABLE `parent` ( `id` int(11) NOT NULL AUTO_INCREMENT, `data` text, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8; CREATE TABLE `child` ( `parent_id` int(11) DEFAULT NULL, `related_ids` int(11) DEFAULT NULL, KEY `parent_id` (`parent_i...

get keyname for constraint error in PHP/MySql?

If I try to do an insert that fails because of a key constraint error, is there a way I can get the name of the key without doing string parsing of the error text? I already know the error code is 1062; I want to find out which key constraint failed :) ...

HSQLDB: weird "unique constraint or index violation" with data read from CSV

Hi, I have a tool which reads a CSV file, selects from it using HSQLDB, and saves the result as another CSV file. More here: http://ondra.zizka.cz/stranky/programovani/java/apps/CsvCruncher-csv-manipulation-sql.texy Now when I used it for some task, I have got: java -jar CsvCruncher-1.0.jar result.csv foo.csv 'SELECT * FROM indata' I...

how to check and alter constraints

hi can anyone tel me how to check whether a primary key exists or not in a table and add a primary key if not exixts in sql server compact(.sdf).. i'm using this, IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE = 'PRIMARY KEY') BEGIN alter table [tablename] add constraint [name] PRIM...

Check constraints in Ms Sql Sever 2005

Hi , I am trying to add a check constraint which verity if after an update the new value (which was inserted) is greater than old values which is already stored in table. For example i have a "price" column which already stores value 100, if the update comes with 101 the is ok, if 99 comes then my constraint should reject the update p...

Reusing CHECK CONSTRAINTS

Hello, In SQL Server assuming one has columns that need to have the same data type is it possible to define a check constraint at the table (or database level) and apply that to a column when you define it? As in this (contrived) example: ALTER TABLE dbo.tblAuditTrail ADD CONSTRAINT CK_DecimalNumber CHECK (DecimalColumn LIKE '^\-?\d+\...

Liquibase drop constraint without knowing it's name

We use liquibase to keep track of our database changes.. First changeSet contains those lines: <column name="SHORT_ID" type="INTEGER"> <constraints unique="true" /> </column> Basically it means that SHORT_ID column has unique constraint but the name of this constraint can be whatever and usually is different each time (we run some ...

Datatable not null constraint

Hi! I need to implement on a datatable a not null constraint,to work and be used in the same way as the UniqueConstraint. Any ideas? ...

Howto delete FK and all dependent table entries?

This is the case. There are 3 tables - state, region and city. If I delete a state with the name "France", I want that all regions and cities belonging to this state be deleted as well. How to do this in T-SQL? ...

F# Generic Programming - Using members

Suppose I have a family of types which support a given member function, like the Property member below: type FooA = {...} with member this.Property = ... type FooB = {...} with member this.Property = ... Suppose the member Property returns an integer for each of the the above types. Now, I wan to write a generic function th...

Are unique constraints on the DB necessary?

I've been wondering lately. Lets say we're doing a webapp with JSF+Spring+JPA/Hibernate (or well any other technologies) and lets say we have a "User" entity. We want the User to have a unique login. If we want to do it then we can put a @UniqueConstraint on the "Login" column, but still our application has to check during user registrat...

C# generics constraint: must define an overloaded operator

Possible Duplicates: Solution for overloaded operator constraint in .NET generics Define a generic that implements the + operator Hi, So I have a generic class MyClass<T> and I want to put a constraint that the type T must define an operator, for example public static T operator +(T x,T y). Is that possible? If not, I was...

Merge Data from Multiple Remote SQL Databases into One SQL Master DB

Hi, Well, I'm sure this question has been asked before but I'm yet to find a single solid answer to it. I'm in the process of creating a solution that involves remote offices uploading data to one master db via web service. Basically, each office will have a windows service that runs every 1hr or so, picks up any new data into a dataset...

Sub-query in tuple constraint DB2

Hi, In my database course we use a book (Database System - the Complete Book) which says the following is a valid create table statement in standard SQL: CREATE TABLE Participants ( meetid INT NOT NULL, -- ... CONSTRAINT RoomConstraint CHECK (1 >= ALL (SELECT num FROM Numbers) ); But DB2 complains and gives 20 pos...

How to check constraints between elements in a list / is this Constraint Programming?

I have many variable-sized lists containing instances of the same class with attribute foo, and for every list I must apply rules like: if there's an element foo=A there cannot be elements with foo in [B,C,D] if there's an element foo=X there must by at least one with foo in [Y,Z] there can be between MIN and MAX elements foo=BAR com...

Insert problem in oracle database

HRESULT: 0X80040E2F (DB_E_INTEGRITYVIOLATION) Error message: Value violated the integrity constraints for a column or table. Can anybody tell me how to solve this error. ...

Stop Hibernate from creating not-null constraints

Is there a way to stop Hibernate from creating not-null constraints for properties annotated with @javax.validation.constraints.NotNull when using hbm2ddl = create? ...

Entity Framework: How to properly handle exceptions that occur due to SQL constraints

Hi all I use Entity Framework to access my SQL data. I have some constraints in the database schema and I wonder how to handle exceptions that are caused by these constraints. As example, I get the following exception in a case where two users try to add an (almost) identical entity to the DB concurrently. System.Data.UpdateException ...

Adding constraints is DDL or DML

Adding constraints in sql server comes under which category DML or DDL? ...

In phpMyAdmin, constraints cause weird dropdowns when editing or inserting

I have added some constraints to some MySQL table fields. This seems to change phpMyAdmin a little bit, including constrained fields being presented as drop down boxes in edit or insert mode: This looks a bit weird to me, as if phpMyAdmin wants to add titles but doesn't have the correct information. Am I correct in this assumption? A...