unique-constraint

How to insert a row and ignore only UNIQUE contraint errors, without using SELECT

可紊 提交于 2020-01-16 18:22:10
问题 I have a table with a column that must have UNIQUE values (but it could be also a multiple-column UNIQUE index, the problem is the same). In my PHP script I have to insert a row in that table. I'm searching for a way, not MySQL-specific, to exit the PHP script if there's a problem, and the problem is not a violation of a UNIQUE constraint. To make things more easy I don't want to use a SELECT query before :D Currently I'm doing something like this: try { $stmt = $dbh->prepare($someinsertquery

PK violated in oracle sql

梦想的初衷 提交于 2020-01-16 00:46:42
问题 I wonder if anyone can help me with this. I ran the whole thing in sql but its gives me this error: Error report: SQL Error: ORA-00001: unique constraint (GAMES.ATHLETE_PK) violated 00001. 00000 - "unique constraint (%s.%s) violated" *Cause: An UPDATE or INSERT statement attempted to insert a duplicate key. For Trusted Oracle configured in DBMS MAC mode, you may see this message if a duplicate entry exists at a different level. *Action: Either remove the unique restriction or do not insert

Create unique constraint with nvl in Oracle

北城余情 提交于 2020-01-15 11:25:48
问题 How can I create unique constraint when I need to treat null values as equals. For alter table T1 add constraint T1_UN unique (nvl(C1, ' ')) i get ORA-00904: : invalid identifier points on nvl Thanks! 回答1: NOT NULL seems like a better idea, but you could make a function-based index unique: create unique index idx_t1 on t1 (nvl(C1, ' ')); 回答2: Just make the column NOT NULL . The nature of NULL is that it is never equal to anything. Hence every NULL value in your column is already UNIQUE in a

How to insert nextval to trigger inside for loop

久未见 提交于 2020-01-14 06:29:10
问题 Here is a code for trigger and it have a for loop. When trigger is fired (INSERT OR UPDATE) there's another table data must include it is MICL_SUP OPEN projMgrsCursor; LOOP FETCH projMgrsCursor INTO projMgr; select micl_sup_id_seq.nextval into SUPID from dual; insert into MICL_SUP VALUES ((SUPID), (SELECT SYSDATE FROM DUAL), :NEW.ENTRYADDEDBY_EMP_NO, 3000, 0,projMgr, NULL,:NEW.EMP_NO); END LOOP; CLOSE projMgrsCursor; This is the table structure. Sup_ID primary and unique key . I can't make

CoreData unique constraints disappears in Xcode

我的梦境 提交于 2020-01-11 11:29:47
问题 What I want to do: Add a unique constraint on the attribute photoID in the entity PhotoUpload . Problem: I tap on constraints and add photoID . When I navigate to a different file and come back to the xcdatamodeld file, the constraint is not present. It is automatically removed. And so the unique constraint is not working. What I have done so far: I have tried deleting the xcdatamodeld file and re-created it, but the same problem persists. Screenshot: Versions: Xcode - 7.3.1 回答1: I believe

UNIQUE constraint controlled by a bit column

最后都变了- 提交于 2020-01-09 11:10:53
问题 I have a table, something like FieldsOnForms( FieldID int (FK_Fields) FormID int (FK_Forms) isDeleted bit ) The pair (FieldID,FormID) should be unique, BUT only if the row is not deleted (isDeleted=0). Is it possible to define such a constraint in SQLServer 2008? (without using triggers) P.S. Setting (FieldID, FormID, isDeleted) to be unique adds the possibility to mark one row as deleted, but i would like to have the chance to set n rows (per FieldID,FormID) to isDeleted = 1, and to have

What is the good approach to check an existance of unique values in database table by SqlAlchemy in python2.7

試著忘記壹切 提交于 2020-01-07 03:07:29
问题 I use session.merge in SqlAlchemy to insert data to the table with UniqueConstraint , which is common for several columns, for example, my ORM class has the following: UniqueConstraint("attr_1", "attr_2", "attr_3", name="attributes_uix") Should I use filter or filter_by with _and to check, if data, which I'm going to insert will violate this unique constraint, or is it the proper way to catch IntegrityError by try - except construction? 回答1: No an sql-alchemy expert but have struggled with

SQL query to get primary keys for all tables in sybase ase 15.x along with column names

[亡魂溺海] 提交于 2020-01-06 23:43:07
问题 I'm using Sybase ASE 15.5 and a stranger to this database. Straight to the point--> I'm looking for a sql query that would help me get the primary keys for all tables in sybase along with the column names on which the primary key is declared. For example, if I have the following tables, organization having primary key PK_org_id on the column org_id org_alias having primary key PK_alias_id on the column alias_id org_temp having primary key PK_org_temp_id on the columns (org_id,org_name) then

Postgres constraint

▼魔方 西西 提交于 2020-01-03 03:34:11
问题 Is there a way in postgres to create a constraint that works like so: I have an entity that has a value "time_of_day". This value can either be morning, afternoon, evening, day, night or anytime. SO I am trying to figure out how to allow the following combinations: Anytime (cannot have anything else) i.e. there can only be one row if anytime is chosen Morning, or Afternoon - can be many rows, but none can contain 'Anytime'. Also cannot be two rows of the same type e.g. two 'morning' rows. (2)

PHP MySQL INSERT fails due to unique constraint

岁酱吖の 提交于 2020-01-03 03:06:08
问题 On insert I am catching the unique constraint mysql_errno() 1062. This works fine but I want to find the existing row to re-instate or modify it. Is there are method to obtain the row id on insert fail? I tried mysql_insert_id() but realised that would only return the row I'm inserting (or failed to insert) therefore, I get 0. Is there no option but to issue another mysql_query and simply perform a select on the duplicate value? I just want to make sure there is no better, quicker, more