unique-constraint

How to enforce unique constraint with LINQ to SQL

佐手、 提交于 2020-01-01 19:26:31
问题 I'd like to enforce a unique constraint on two columns with LINQ to SQL. I have got a constraint configured on a SQL table, but is there a way to use it with LINQ to SQL? Unique constraint is applied to two columns, both of which are foreign keys. Thank you Edit: I could catch exception, that's if a very specific exception gets thrown. Alternative is to check state of the table before running any updates/inserts. All seems to be like too much work for a very simple task. 回答1: In my opinion,

MySQL Enforce Unique constraint across a Combination of Rows

不羁的心 提交于 2019-12-31 02:55:11
问题 I am refining a Search Auto-suggestion system, and after a few iterations and Normalization, have the following set of tables: DB Fiddle : https://www.db-fiddle.com/f/b1FvGDkBMQXkREaMh3pHKi/0 Table 1: keywords - It stores a list of alphanumeric (relevant) keywords. Relevant details are: CREATE TABLE keywords ( keyword_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, keyword VARCHAR(32) NOT NULL /* Other fields eg: ranking, weights, etc */ ) engine = innodb; | keyword_id | keyword | | ----

Does a Postgres UNIQUE constraint imply an index?

岁酱吖の 提交于 2019-12-28 04:31:07
问题 When adding a unique constraint to a Postgres table does that imply that an index has also been added to that table? Meaning, if I add a UNIQUE constraint on a text column, does that text column now have an index or does an index have to be added separately? 回答1: Yes. UNIQUE constraints are implemented using a btree index in Postgres. Details: How does PostgreSQL enforce the UNIQUE constraint / what type of index does it use? 来源: https://stackoverflow.com/questions/29655439/does-a-postgres

Add a unique constraint over muliple reference columns

陌路散爱 提交于 2019-12-25 04:37:13
问题 Hello i want to add a unique constraint over two referenced columns: @Entity() @Table(uniqueConstraints = @UniqueConstraint(columnNames = { "ast", "tfs" })) public class N extends UUID { @ManyToOne(optional = false) @JoinColumn(name = "ast") private A ast; @ManyToOne(optional = false) @JoinColumn(name = "tfs") private T tfs; In Class UUID is logic for generating a Primary ID. Hibernate generates 3 Constraint, PK, 2 Secondary Keys.. but i am expecting 4 Constraints. Does someone have a idea ?

JPA annotation and ConstraintViolationException

泪湿孤枕 提交于 2019-12-25 04:09:11
问题 This question is being asked/mentioned over and over but I could not find if I am doing something wrong or that the problem is "real": I have an entity class for a simple Oracle table in which there is one field that should be unique. It has a unique constraint in the DB. In the entity definition I added the JPA annotation - @Entity @Table(name = "tbl", uniqueConstraints = @UniqueConstraint(columnNames = "uni_field")) public class MyTable implements Serializable { ... @Column(name = "uni

JPA annotation and ConstraintViolationException

跟風遠走 提交于 2019-12-25 04:08:18
问题 This question is being asked/mentioned over and over but I could not find if I am doing something wrong or that the problem is "real": I have an entity class for a simple Oracle table in which there is one field that should be unique. It has a unique constraint in the DB. In the entity definition I added the JPA annotation - @Entity @Table(name = "tbl", uniqueConstraints = @UniqueConstraint(columnNames = "uni_field")) public class MyTable implements Serializable { ... @Column(name = "uni

Creating custom unique constraints

牧云@^-^@ 提交于 2019-12-25 03:55:46
问题 I Defined my @FuSsA_UniqueKey constraint annotation: package com.fussa.employee.util; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import javax.validation.Constraint; import javax.validation.Payload; @Constraint(validatedBy = { UniqueIDValidator.class }) @Target({ ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface FuSsA_UniqueKey { String columnNames();

org.hibernate.AnnotationException: Unable to create unique key constraint

你说的曾经没有我的故事 提交于 2019-12-25 03:28:13
问题 I am using hibernate 4.3.5.Final version. To handle reserve words at Database,I used a property in hibernate hibernate.globally_quoted_identifiers = true. And My pojo class having a unique column and it looks like @Entity @Table(name="theme1" ,catalog="theme2" , uniqueConstraints = @UniqueConstraint(columnNames={"name1"}) public class Theme1 implements java.io.Serializable { @Id @GeneratedValue(strategy=IDENTITY) private Integer id; @Column(name="name1", unique=true, nullable=false, length=32

Replace path string in SQLite DB causes unexpected violated unique constraint

时间秒杀一切 提交于 2019-12-25 00:13:56
问题 I'm not sure whether I've found a bug in SQLite or whether I'm simply not using it correctly. I'm storing relative file paths (as you know them from UNIX file systems) in a DB. For safety I've marked the column to be unique. Below is a self-explanatory example where the last command unexpectedly fails with a violated UNIQUE constraint. My goal is to rename the directory with path "a" to "d" CREATE TABLE test (db_id INTEGER PRIMARY KEY, path TEXT UNIQUE); INSERT INTO test (path) VALUES ('a');

SQLite table constraint unique and ON CONFLICT REPLACE usage

谁说胖子不能爱 提交于 2019-12-24 07:25:07
问题 Please read before make it Duplicate. I am trying to insert longitude and latitude values in SQLite table and i want it to be unique value, after some research for that i have found this and this answers very helpful, although they both are written for simple queries and i am not able to find how to fit my query with both constraints unique and ON_CONFLICTION_REPLACE query is as follow, private static final String CREATE_USER_TABLE = "CREATE TABLE IF NOT EXISTS " + TABLE_LOCATIONS + "(" + UID