unique-constraint

Mysql unique constraint allowing single row for a combination

为君一笑 提交于 2019-12-04 04:27:15
问题 Is it possible to have a unique constraint such that one particular column has a value only once? For instance ----------------------- name | price | default ----------------------- XYZ | 20 | TRUE ----------------------- XYZ | 30 | FALSE ----------------------- XYZ | 40 | FALSE ----------------------- ABC | 50 | FALSE ----------------------- So in above table, for a particular name value, default value can be TRUE only once. And will have a unique constraint on name & price columns. Is this

Unique constraint not created in JPA

夙愿已清 提交于 2019-12-04 03:20:04
问题 I have created the following entity bean, and specified two columns as being unique. Now my problem is that the table is created without the unique constraint, and no errors in the log. Does anyone have an idea? @Entity @Table(name = "cm_blockList", uniqueConstraints = @UniqueConstraint(columnNames = {"terminal", "blockType"})) public class BlockList { @Id @GeneratedValue(strategy = GenerationType.AUTO) private int id; @ManyToOne(cascade = CascadeType.PERSIST) @JoinColumn(name="terminal")

Oracle 'INSERT ALL' ignore duplicates

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 03:05:27
问题 I have a database table with a unique constraint on it (unique (DADSNBR, DAROLEID) pair). I am going to be inserting multiple values into this table simultaneously, so I'd like to get it done using one query - I'm assuming this would be the faster way. My query is thus: INSERT ALL INTO ACCESS (DADSNBR, DAROLEID) VALUES (68, 1) INTO ACCESS (DADSNBR, DAROLEID) VALUES (68, 2) INTO ACCESS (DADSNBR, DAROLEID) VALUES (68, 3) INTO ACCESS (DADSNBR, DAROLEID) VALUES (68, 4) SELECT 1 FROM DUAL Since

PostgreSQL multiple nullable columns in unique constraint

混江龙づ霸主 提交于 2019-12-04 02:47:15
问题 We have a legacy database schema that has some interesting design decisions. Until recently, we have only supported Oracle and SQL Server, but we are trying to add support for PostgreSQL, which has brought up an interesting problem. I have searched Stack Overflow and the rest of the internet and I don't believe this particular situation is a duplicate. Oracle and SQL Server both behave the same when it comes to nullable columns in a unique constraint, which is to essentially ignore the

Hibernate - clearing a collection with all-delete-orphan and then adding to it causes ConstraintViolationException

空扰寡人 提交于 2019-12-04 00:18:57
I have these entities class Foo{ Set<Bar> bars; } class Bar{ Foo parent; String localIdentifier; } With this mapping (sorry, no annotations, I'm old fashioned): <class name="Foo"> ... <set name="bars" cascade="all-delete-orphan" lazy="false" inverse="true"> <key>...</key> <one-to-many class="Bar"/> </set> </class> <class name="Bar"> ... <property name="localIdentifier" column="local_identifier"/> <many-to-one name="parent" column="parent_id" /> </class> I also have a unique constraint on 2 columns: local_identifier and parent_id (not a unique constrain on each, but a single unique constrain

UNIQUE Constraint, only when a field contains a specific value

試著忘記壹切 提交于 2019-12-04 00:18:56
问题 I'm trying to create a UNIQUE INDEX constraint for two columns, but only when another column contains the value 1. For example, column_1 and column_2 should be UNIQUE only when active = 1 . Any rows that contain active = 0 can share values for column_1 and column_2 with another row, regardless of what the other row's value for active is. But rows where active = 1 cannot share values of column_1 or column_2 with another row that has active = 1 . What I mean by "share" is two rows having the

Should I specify both INDEX and UNIQUE INDEX?

旧巷老猫 提交于 2019-12-03 23:19:20
On one of my PostgreSQL tables, I have a set of two fields that will be defined as being unique in the table, but will also both be used together when selecting data. Given this, do I only need to define a UNIQUE INDEX, or should I specify an INDEX in addition to the UNIQUE INDEX? This? CREATE UNIQUE INDEX mytable_col1_col2_idx ON mytable (col1, col2); Or this? CREATE UNIQUE INDEX mytable_col1_col2_uidx ON mytable (col1, col2); CREATE INDEX mytable_col1_col2_idx ON mytable (col1, col2); Mark Byers If you have a UNIQUE INDEX then you don't also need the INDEX - it would be redundant. A UNIQUE

How can I specify a unique constraint for attributes using the <xs:unique> as a child element of the <xs:element> tag?

我怕爱的太早我们不能终老 提交于 2019-12-03 21:23:35
问题 If I have the following element spec in XSD I can add the <xs:unique> constraint as a child of <xs:element name="Parent"> but I can't get it to work as a child of <xs:element name="Child"> : <xs:element name="Parent"> <xs:complexType> <xs:element name="Child" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:attribute name="Key" type="xs:string" use="required" /> </xs:complexType> <!-- Option A: insert unique constraint here with selector . --> </xs:element> </xs:complexType> <!--

Migrate Django model to unique_together constraint

时光总嘲笑我的痴心妄想 提交于 2019-12-03 12:57:55
I have a model with three fields class MyModel(models.Model): a = models.ForeignKey(A) b = models.ForeignKey(B) c = models.ForeignKey(C) I want to enforce a unique constraint between these fields, and found django's unique_together , which seems to be the solution. However, I already have an existing database, and there are many duplicates. I know that since unique_together works at the database level, I need to unique-ify the rows, and then try a migration. Is there a good way to go about removing duplicates (where a duplicate has the same (A,B,C)) so that I can run migration to get the

Core Data (After Adding Unique Constraint) : annotation: repairing missing delete propagation for to-many relationship

吃可爱长大的小学妹 提交于 2019-12-03 12:36:14
This issue started occurring after we added Unique key i.es Constraint. Frequently updating Meeting managed object deletes the event managed object which has a to-one inverse relationship from meeting managed object. Error CoreData: annotation: repairing missing delete propagation for to-many relationship meetingList on object 0x60c00009c4d0 (0x60c000621e40 ) with bad fault 0x60800009ac20 (0x60800023a360 ) Data Model I have three entities in my core data model i.es (CDEvent, CDMeeting, CDMLCheckin) . Entity Properties and Relationship as described below: Relationship Properties: CDEvent