constraints

How to create a “unique” constraint on a boolean Mysql column?

时光怂恿深爱的人放手 提交于 2019-11-28 09:03:58
I would like to add a BOOLEAN column to a MySQL table which will be named is_default . In this column, only one record can have is_default set to true . How can I add this constraint to my column with mysql? Thanks! UPDATE If it is not a constraint that I should add. How are we dealing with this type of problem on DBs? I think this is not the best way to model the situation of a single default value. Instead, I would leave the IsDefault column out and create a separate table with one row and only the column(s) that make(s) up the primary key of your main table. In this table you place the PK

How to handle JPA unique constraint violations?

醉酒当歌 提交于 2019-11-28 08:59:31
When a unique constraint is violated, a javax.persistence.RollbackException is thrown. But there could be multiple reasons to throw a RollbackException . How can I find out that a unique constraint was violated? try { repository.save(article); } catch(javax.persistence.RollbackException e) { // how to find out the reason for the rollback exception? } Pascal Thivent How can I find out that a unique constraint was violated? Exception are chained, you have to call getCause() recursively to get the provider specific exception (and maybe go down to the SQLException ) to translate it into something

Disabling foreign key constraint, still can't truncate table? (SQL Server 2005)

本秂侑毒 提交于 2019-11-28 08:07:09
I have a table called PX_Child that has a foreign key on PX_Parent. I'd like to temporarily disable this FK constraint so that I can truncate PX_Parent. I'm not sure how this goes however. I've tried these commands ALTER TABLE PX_Child NOCHECK CONSTRAINT ALL ALTER TABLE PX_Parent NOCHECK CONSTRAINT ALL (truncate commands) ALTER TABLE PX_Child CHECK CONSTRAINT ALL ALTER TABLE PX_Parent CHECK CONSTRAINT ALL But the truncate still tells me it can't truncate PX_Parent because of a foreign key constraint. I've looked all around the net and can't seem to find what I'm doing wrong, sorry for the

Changing MySQL primary key when foreign key contraints exist

空扰寡人 提交于 2019-11-28 07:27:08
问题 I have two already-existing tables which look (in part) roughly like this: CREATE TABLE parent ( old_pk CHAR(8) NOT NULL PRIMARY KEY ) ENGINE=InnoDB; CREATE TABLE child ( parent_key CHAR(8), FOREIGN KEY (parent_key) REFERENCES parent(old_pk) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB; I want to add a new auto-incrementing integer id column to parent and use it as the primary key instead, while still keeping old_pk as a unique key and allowing other tables like child to reference it

XML Serialize boolean as 0 and 1

試著忘記壹切 提交于 2019-11-28 07:18:11
问题 The XML Schema Part 2 specifies that an instance of a datatype that is defined as boolean can have the following legal literals {true, false, 1, 0}. The following XML, for example, when deserialized, sets the boolean property "Emulate" to true . <root> <emulate>1</emulate> </root> However, when I serialize the object back to the XML, I get true instead of the numerical value. My question is, is there a way that I can control the boolean representation in the XML? 回答1: You can implement

How do I DROP a constraint from a sqlite (3.6.21) table?

狂风中的少年 提交于 2019-11-28 07:08:10
I have the following table: CREATE TABLE child( id INTEGER PRIMARY KEY, parent_id INTEGER CONSTRAINT parent_id REFERENCES parent(id), description TEXT); How do I drop the constraint? SQLite does not (as of this answer) support the alter table drop constraint command. The allowed syntax can be seen here . You will need to create a new table without a constraint, transfer the data, then delete the old table. I think something like the following should work: CREATE TABLE child2 ( id INTEGER PRIMARY KEY, parent_id INTEGER, description TEXT ); INSERT INTO child2 (id, parent_id, description) SELECT

Finding out reason of Pyomo model infeasibility

谁说我不能喝 提交于 2019-11-28 06:46:30
问题 I got a pyomo concrete model with lots of variables and constraints. Somehow, one of the variable inside my model violates one constraint, which makes my model infeasible: WARNING: Loading a SolverResults object with a warning status into model=xxxx; message from solver=Model was proven to be infeasible. Is there a way to ask the solver, the reason of the infeasibility? So for example, lets assume I got a variable called x , and if I define following 2 constraints, model will be ofc.

Disable Autolayout Localization Behavior (RTL - Right To Left Behavior )

纵然是瞬间 提交于 2019-11-28 06:19:55
My application is localized in both English and Arabic. Unfortunately, sometimes the autolayout behavior for localization is not required. By that, I mean reversing the leading and trailing spaces. I want to override this behavior. Is there any way to do that? To make leading act always as left (and trailing always like right), i.e. make it language independent, you can remove checkmark on "Respect language direction" on all constrains. You can find this checkmark in constrain settings in the Attributes inspector under "First Item" button. The attributes leading and trailing are the same as

Equivalent to exclusion constraint composed of integer and range

风格不统一 提交于 2019-11-28 06:04:00
问题 I need to have something equivalent to this exclusion constraint drop table if exists t; create table t ( i int, tsr tstzrange, exclude using gist (i with =, tsr with &&) ); ERROR: data type integer has no default operator class for access method "gist" HINT: You must specify an operator class for the index or define a default operator class for the data type. I guess the problem is obvious from the error message. How to do it? 回答1: You need to install the additional module btree_gist to make

How can I create a SQL unique constraint based on 2 columns?

霸气de小男生 提交于 2019-11-28 04:28:04
I have a Table like this one: |UserId | ContactID | ContactName --------------------------------------- | 12456 | Ax759 | Joe Smith | 12456 | Ax760 | Mary Smith | 12458 | Ax739 | Carl Lewis | 12460 | Ax759 | Chuck Norris | 12460 | Bx759 | Bruce Lee I need to add a constraint to this table so that no user can have duplicate contact id's. The users are importing data from various external systems so ContactId will not be unique across the board but will be unique on a per user basis. I know how to create Unique and Non-Null contraints based on single columns but how can I create a unique