unique-constraint

Unique values for two columns in Doctrine

醉酒当歌 提交于 2019-12-23 18:23:05
问题 I have entity called Dimension. It has three attributes - ID, width and height. ID is primary key. In the table, the dimension should be unique so there has to be only one record with given dimension (for example 40x30). What constraints I need to set? Is uniqueConstraints={@UniqueConstraint(name="dimension", columns={"width", "height"})} correct? 回答1: From the documentation, @UniqueConstraint annotation is used inside the @Table annotation on the entity-class level. It allows to hint the

When does Postgres check unique constraints?

独自空忆成欢 提交于 2019-12-23 11:33:12
问题 I have a column sort_order with a unique constraint on it. The following SQL fails on Postgres 9.5: UPDATE test SET sort_order = sort_order + 1; -- [23505] ERROR: duplicate key value violates unique constraint "test_sort_order_key" -- Detail: Key (sort_order)=(2) already exists. Clearly, if the sort_order values were unique before the update, they will still be unique after the update. Why is this? The same statement works fine on Oracle and MS SQL, but also fails on MySQL and SQLite. Here's

When does Postgres check unique constraints?

℡╲_俬逩灬. 提交于 2019-12-23 11:32:46
问题 I have a column sort_order with a unique constraint on it. The following SQL fails on Postgres 9.5: UPDATE test SET sort_order = sort_order + 1; -- [23505] ERROR: duplicate key value violates unique constraint "test_sort_order_key" -- Detail: Key (sort_order)=(2) already exists. Clearly, if the sort_order values were unique before the update, they will still be unique after the update. Why is this? The same statement works fine on Oracle and MS SQL, but also fails on MySQL and SQLite. Here's

Reject PDO MySQL statement if a specified value is found in a field?

橙三吉。 提交于 2019-12-23 05:14:00
问题 I've searched Google but not had much luck with this, so maybe SO can help. I am developing a user authentication system for a couple of projects and need to ensure that the email address, which is also the username, is unique. I set the field as unique in the MySQL query, but I need a way to cancel an SQL query and notify the user that "the specified email is already in use" if the supplied email matches an existing record. I could do a select query before the insert, but I am wondering if

How to find out line number, procedure name in PL/SQL in case of an error

白昼怎懂夜的黑 提交于 2019-12-23 02:38:41
问题 I am using a D2k 6i form and getting the error on form from stored database(oracle9i) procedure ORA-00001:Unique constraint(.) violated but i m not able to trace out from which procedure it is coming. can anybody help me regarding this 回答1: For posterity, here is the solution the OP found: ok in D2k forms there is an ON-ERROR trigger where you can use the function DBMS_ERROR_TEXT to get the procedure,package name line number of the statement from where the error is coming 回答2: I've come

How to create a Postgres table with unique combined primary key?

只愿长相守 提交于 2019-12-22 08:32:51
问题 I have two tables named players & matches in a Postgres DB as follows: CREATE TABLE players ( name text NOT NULL, id serial PRIMARY KEY ); CREATE TABLE matches ( winner int REFERENCES players (id), loser int REFERENCES players (id), -- to prevent rematch btw players CONSTRAINT unique_matches PRIMARY KEY (winner, loser) ); How can I ensure that only a unique combination of either (winner, loser) or (loser, winner) is used for matches primary key so that the matches table won't allow the

How to do multiple column unique-constraint in ormlite ( SQLite )

别等时光非礼了梦想. 提交于 2019-12-22 04:32:16
问题 I'm using ormlite for Android and I'm trying to get a multiple column unique-constraint. As of now i'm only able to get a unique constraint on indiviudal columns like this: CREATE TABLE `store_group_item` (`store_group_id` INTEGER NOT NULL UNIQUE , `store_item_id` INTEGER NOT NULL UNIQUE , `_id` INTEGER PRIMARY KEY AUTOINCREMENT ); and what I want is CREATE TABLE `store_group_item` (`store_group_id` INTEGER NOT NULL , `store_item_id` INTEGER NOT NULL , `_id` INTEGER PRIMARY KEY AUTOINCREMENT,

What is the difference between UNIQUE, UNIQUE KEY and CONSTRAINT 'name' UNIQUE?

那年仲夏 提交于 2019-12-22 02:06:54
问题 I have a basic users table I want to create in MySQL. I do not want duplicate emails or duplicate usernames appearing in the database. What is the best way of preventing this upon table creation? And what is the difference between the following: 1. UNIQUE (username), UNIQUE (email), 2. UNIQUE KEY (username), UNIQUE KEY (email), 3. CONSTRAINT ucons_login UNIQUE (username, email), I assume some of these are synonymous, yet I've been reading conflicting information online and was seeking

SQL constraint to check whether value doesn't exist in another table

有些话、适合烂在心里 提交于 2019-12-21 20:23:06
问题 In my PostgreSQL 9.4 database, I have a table fields with a column name with unique values. I'm creating a new table fields_new with a similar structure (not important here) and a column name as well. I need a way to constraint name values to be inserted to the fields_new not to be present in fields.name . For example, if fields.name contains the values 'color' and 'length' , I need to prevent fields_new.name from containing 'color' or 'length' values. So, in other words I need to provide

Hibernate / JPA many to many relationship through a join table and a composite key, Unique Constraint issue

て烟熏妆下的殇ゞ 提交于 2019-12-21 17:24:45
问题 So I asked this question yesterday, but the goal posts have changed and the question is different: Hibernate / JPA Collection of Elements with Many to Many relationship? I want to know if it's possible to create entities that will model my required relationship so that Hibernate will create my schema when I fire up my application. The relationship I want looks like this: 1 http://a8.sphotos.ak.fbcdn.net/hphotos-ak-ash4/417593_10150594114269218_505554217_8657377_1475865815_n.jpg The thing is